Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Subquery failing
Message
 
 
À
18/07/2011 11:37:04
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01518439
Message ID:
01518443
Vues:
60
>Here we are again
>
>
>select individual_ref from contact where individual_ref in (190999,191000,191001,191002)
>
>
>returns
>
>191002
>191002
>
>there are 2 matching records. Thats correct
>
>
>
>select individual_ref from individual where family_ref = 190997
>
>
>returns
>
>190999
>191000
>191001
>191002
>
>again thats correct
>
>So why would
>
>
>select i.individual_ref from individual i where not EXISTS (select c.individual_ref from contact c ) 
>
>
>return no rows ?
>
>I'm expecting
>
>190999
>191000
>191001
>
>any ideas .
>
>Thanks

Because your subquery is not linked to the main query. It should be:
select i.individual_ref from individual i 
where not EXISTS (select 1 from contact c where c.individual_ref = i.Individual_Ref ) 
The way you wrote your query just checks if the Contact table has at least one row. If it's true, it will return 0 records.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform