Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is more performant : EXISTS or IN ?

Status
Not open for further replies.

ScanX

Programmer
Joined
Oct 13, 2003
Messages
26
Location
BE
Hi

I'm wondering what is supposed to be more performant between an EXISTS or an IN because I always receive different performance results.

Maybe someone can tell me which on is IN GENERAL more performant.

Example :

IN :
----

SELECT
count(distinct DBA.fac_ind_opts.ind_key)
FROM
DBA.fac_ind_opts
WHERE
DBA.fac_ind_opts.ind_key IN (SELECT A.ind_key
FROM DBA.fac_ind_opts A,
DBA.dim_opts B,
DBA.dim_individual C
WHERE A.opts_key = B.opts_key
AND A.ind_key=C.ind_key
)


EXISTS :
--------

SELECT
count(distinct DBA.fac_ind_opts.ind_key)
FROM
DBA.fac_ind_opts
WHERE
EXISTS (SELECT 1
FROM DBA.fac_ind_opts A,
DBA.dim_opts B,
DBA.dim_individual C
WHERE A.opts_key = B.opts_key
AND A.ind_key=C.ind_key
AND DBA.fac_ind_opts.ind_key = A.ind_key
)


Thanx for help
 
or maybe the combination of an (NOT) EXISTS and an (NOT) IN
in the same query can affect the results too ?

by the way : isn't it possible to edit posts ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top