Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IN subquery, with multiple fields
Message
From
31/10/2016 10:42:40
 
 
To
31/10/2016 10:12:17
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01642525
Message ID:
01642529
Views:
69
>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.
>
>Regards,
>
>Hilmar.

You can achieve NOT IN with LEFT JOIN and then check in WHERE clause for some field to be NULL
select *
from MainTable 
LEFT JOIN LookupTable ON MainTable.KeyField1 = LookupTable.KeyField1 AND MainTable.KeyField2 = LookupTable.KeyField2
WHERE LookupTable.PKField IS NULL
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform