Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Help
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00638949
Message ID:
00638955
Vues:
22
>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--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform