Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to change JOIN to exclude?
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01339003
Message ID:
01339008
Views:
16
This message has been marked as the solution to the initial question of the thread.
>>
>>select * from mytable1 LEFT join mytable2 on mytable1.fld1 = mytable2.fld1 where myTable2.fld1 IS NULL
>
>But the value in MyTable2.fld1 is not NULL. It has some entry but the entry has not corresponding value in MyTable1.
>
>Thank you.

The select I posted will return all records in table1 that do not have child records in table2. Try it.
select my.* from mytable1 my LEFT join mytable2 my2 on my.fld1 = my2.fld1 where my2.ID IS NULL
Also please notice that I use LEFT JOIN, not INNER JOIN. Left JOIN returns all records from the left table even if we don't have matching records in the right table (table2). By using IS NULL condition on the second table we retrive only non-matching records.

This performs better than NOT IN query.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform