Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to change JOIN to exclude?
Message
From
14/08/2008 17:27:13
 
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:
01339010
Views:
12
>>>Hi,
>>>
>>>How do I change the following SQL Select so that it will return only those records in MyTable1 that have no child records in MyTable2:
>>>
>>>
>>>select * from mytable1 join mytable2 on mytable1.fld1 = mytable2.fld1
>>>
>>>
>>>Thank you in advance for any help.
>>
>>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.

Think of her query as
SELECT * FROM myTable1 WHERE fld1 NOT IN (SELECT fld1 FROM myTable2)
plus it will add the myTable2 fields to the result with all values populated with NULL.

BTW, this may not be relevant but .... are you sure you wanted SELECT * ??? All fields from both tables are included in the result with common fields being suffixed with _A and _B.

Just a thought.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform