Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Exist or IN in a Where Clause with more conditions

Author  Topic 

shifis
Posting Yak Master

157 Posts

Posted - 2009-09-10 : 22:26:09
Hi
I have a clause that uses an IN condition combine with another condition.

What of these options is better:
Case 1:
SELECT *
FROM OP_SOLICITUDES a
WHERE exists (SELECT IdProm FROM PROMS where a.SOS_ID_PROMOTORIA =PROMS.IdProm)
AND a.SOS_FEC_CREACION BETWEEN (getdate()-30) AND GETDATE() )

Case 2:
SELECT *
FROM OP_SOLICITUDES a
WHERE a.SOS_ID_PROMOTORIA IN(SELECT IdProm FROM PROMS )
AND a.SOS_FEC_CREACION BETWEEN (getdate()-30) AND GETDATE()

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-10 : 22:46:41
this should be helpful
http://weblogs.sqlteam.com/peterl/archive/2009/06/12/Timings-of-different-techniques-for-finding-missing-records.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

shifis
Posting Yak Master

157 Posts

Posted - 2009-09-11 : 14:39:46
Hi,

Thanks for the help.

I still confuse about using EXISTS or IN, I read somo articles about this topic, in some of them they said that is better EXISTS and in others that check the execution plan.
The confusion is because in all the articles they only mention one condition in the WHERE and here I will use more than one condition, maybe in this case is better use one of both.
Go to Top of Page
   

- Advertisement -