Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Help
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00638949
Message ID:
00638955
Views:
20
>I have table1 that has a logic unique key of custn1+custn2. Table2 has multiple records for each custn1+custn2.
>
>I want to find records in table2 whose key is found in table1. I also want to find records in tabl2 whose key is not found in table2.
>
>There are several hundred to several thousand records in these tables.
>
>Thanks
>
>Brenda
* In table1
SELECT * FROM table2 ;
  WHERE custn1+custn2 IN ( SELECT custn1+custn2 FROM table1)
* the same with correlated query (could be slower or faster than previous)
SELECT * FROM table2 t2 ;
  WHERE EXISTS ( SELECT * FROM table1 t1 ;
              WHERE t1.custn1+ t1.custn2 = t2.custn1+ t2.custn2)
* or if you've separate indexes on  custn1 and custn2
SELECT * FROM table2 t2 ;
  WHERE EXISTS ( SELECT * FROM table1 t1 ;
              WHERE t1.custn1 = t2.custn1 And t1.custn2 = t2.custn2)

* Not in table1
SELECT * FROM table2 ;
  WHERE custn1+custn2 NOT IN ( SELECT custn1+custn2 FROM table1)
* for correlated queries just change EXISTS to NOT EXISTS
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform