Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL question
Message
From
13/02/2017 09:46:21
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
01647876
Message ID:
01647897
Views:
88
>Hi:
>I have two tables: table1 and table2. Each has one text field in common: ID, containing a 9 character code that is unique for each record. However, whereas table1 has 10,000 records, table2 has 200. But some of the ID's found in table2 do not exist in table 1. Using set relation and filter, I can find the table1 id's that are missing from table2. I am wondering whether this could also be done with an SQL statement?
>
>
>CLOSE ALL
>USE
>USE table2
>INDEX on id TO id2
>
>SELECT 2
>USE table1
>INDEX on id TO id1
>
>SELECT 1
>SET RELATION TO id INTO table2
>SET FILTER TO table2.id  == " "  && or == ""
>SELECT 2
>DELETE ALL 
>SET FILTER TO 
>SET FILTER TO DELETED()
>BROWSE && for instance
>
>
>I thought that an SQL statement such as the following might be equivalent, but it isn't:
>
>
>SELECT * ;
>FROM table1, table2 ;
>WHERE table1.id <> table3.id 
>
>
>Thank you, Steve


Basically there are 3 ways to do this with SQL:

1) Using "not in"
2) Using left join on checking null
3) Using "not exists"

I would choose "not exists", i.e.:
Select * from (_samples + 'data\Customer') cus ;
   where NOT EXISTS (select * from (_samples+'data\Orders') o where o.Cust_Id = cus.Cust_id)
Ç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
Reply
Map
View

Click here to load this message in the networking platform