Groups | Blog | Home
all groups > sql server clients > january 2004 >

sql server clients : Which one is optimized



Jacco Schalkwijk
1/29/2004 1:47:22 PM
Hi Noorali,

Exists will always perform at least as well as IN, so EXISTS is the better
choice. On top of that, you will have problems with IN when PP_VPatientID
can be NULL. IN won't return any results then.

--
Jacco Schalkwijk
SQL Server MVP


[quoted text, click to view]

Noorali Issani
1/29/2004 6:29:16 PM
I just wanna know that which one query is more optimized one....

1)
select COUNT(*) from patient a where NOT exists (
select PP_VPatientID
FROM PatientPersonnel b
where b.PP_VPatientID = a.PA_VPatientID)


2)
select COUNT(*) from patient where PA_VPatientID NOT IN (
select PP_VPatientID FROM PatientPersonnel)


Waiting for your reply

Noor

Vinodk
1/29/2004 7:19:22 PM
I would vote for the EXISTS clause option normally.

--
HTH,
Vinod Kumar
MCSE, DBA, MCAD, MCSD
http://www.extremeexperts.com

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp


[quoted text, click to view]

ashish
1/29/2004 9:21:44 PM
It will depend on the way indexes are setup...if columns in the join
statement are indexed I would go the 1)

ashish

[quoted text, click to view]

Mike Collier
1/30/2004 7:23:16 PM
[quoted text, click to view]

This tool might give some details:
http://81.130.213.94/myforum/forum_posts.asp?TID=78&PN=1

--
Mike Collier
FREE ADO Inspector tool when you register at ADO forum.
www.adoanywhere.com
http://www.adoanywhere.com/forum

AddThis Social Bookmark Button