Information générale
Forum:
Microsoft SQL Server
Titre:
What am I missing here?
Versions des environnements
SQL Server:
SQL Server 2000
What is the difference in IN (select..) and exists? Whe does the first query return nothing but the second one does?
Thanks
-- tblclaimheader.ilsid and tbllocation.ilsid are both int(4)
select * from tblclaimheader ch
where ch.ilsid not in (select l.ilsid from tbllocation L)
-- returns no records
select * from tblclaimheader ch where ch.ilsid = 1 and
ch.ilsid not in (select l.ilsid from tbllocation L where l.ilsid = 1)
-- returns 1 record
select ch.* from tblclaimheader ch where not exists (select * from tbllocation L where l.ilsid = ch.ilsid)
-- returns 1841 records
select * from tblclaimheader where ilsid = 1
-- returns 1 record
select * from tbllocation where ilsid = 1
-- returns no records
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement