Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting records from two different tables in one query
Message
From
15/03/2010 11:42:28
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
15/03/2010 11:38:41
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01454516
Message ID:
01454568
Views:
47
>>>>There're at least 3 ways you can do that
>>>>
>>>>* 1 - EXISTS subquery
>>>>SELECT * FROM mytable1 WHERE NOT EXISTS (SELECT 1 FROM mytable2 WHERE myfield1 = mytable1.myfield1)
>>>>* 2 - JOIN
>>>>SELECT mytable1.* FROM mytable1 JOIN mytable2 ON mytable2.myfield1 = mytable1.myfield1 ;
>>>>  WHERE mytable2.myfield1 IS NULL
>>>>* 3 - IN subquery
>>>>SELECT * FROM mytable1 WHERE myfield1 NOT IN (SELECT myfield1 FROM mytable2)
>>>>
>>>>The second one most likely will be the fastest in VFP
>>>>
>>>
>>>
>>>Shouldn't #2 be a left join ?
>>
>>Yes, it should be a LEFT JOIN (was a typo, I assume). Check this link http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/the-ten-most-asked-sql-server-questions--1#4
>
>
>bu-bu-but i like number 3 and number 1 must i use number 2?

No. Unless your field accepts null, you don't have to do that.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform