Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IN subquery, with multiple fields
Message
De
31/10/2016 14:08:15
Al Doman (En ligne)
M3 Enterprises Inc.
North Vancouver, Colombie Britannique, Canada
 
 
À
31/10/2016 10:12:17
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01642525
Message ID:
01642535
Vues:
66
>Can the "IN" clause, and a subquery, be used with multiple fields? I believe the answer is "no", but I wanted to confirm this.
>
>Example with one field:
>
>select * from MainTable where KeyField in (select KeyField in LookupTable)
>
>
>For two fields, I was thinking something along the lines of:
>
>select * from MainTable where (KeyField1, KeyField2) in (select KeyField1, KeyField2) in LookupTable
>
>
>But if I remember correctly, that resulted in an error.
>
>Assuming the answer is "no", and with respect to workarounds, I know I can use the "JOIN" instead; but how would I use the JOIN to emulate a NOT IN? I am pretty sure I can achieve this, but I am not sure about a more or less elegant way of doing this.

You might be able to do something like this:
SELECT ;
  Field1 ;
  , Field2 ;
  , Field1 + Field2 AS ComboCol ;
  FROM MainTable ;
  WHERE ComboCol IN ;
    ( SELECT Field1 + Field2 AS SomeCol FROM LookupTable ) ;
  ...
How you create the combination column would be the key thing. Simple for strings, otherwise you might need to CAST the columns to strings or combine some other way.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform