u explain it ur self dear friend
what u want now
Main Topics
Browse All TopicsWhat is the difference between oracle clause "Exists" and "in "
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
ok, will not try to elaborate.
>http://asktom.oracle.com/
Well, the two are processed very very differently.
Select * from T1 where x in ( select y from T2 )
is typically processed as:
select *
from t1, ( select distinct y from t2 ) t2
where t1.x = t2.y;
The subquery is evaluated, distinct'ed, indexed (or hashed or sorted) and then
joined to the original table -- typically.
As opposed to
select * from t1 where exists ( select null from t2 where y = x )
That is processed more like:
for x in ( select * from t1 )
loop
if ( exists ( select null from t2 where y = x.x )
then
OUTPUT THE RECORD
end if
end loop
It always results in a full scan of T1 whereas the first query can make use of
an index on T1(x).
So, when is where exists appropriate and in appropriate?
Lets say the result of the subquery
( select y from T2 )
is "huge" and takes a long time. But the table T1 is relatively small and
executing ( select null from t2 where y = x.x ) is very very fast (nice index on
t2(y)). Then the exists will be faster as the time to full scan T1 and do the
index probe into T2 could be less then the time to simply full scan T2 to build
the subquery we need to distinct on.
Lets say the result of the subquery is small -- then IN is typicaly more
appropriate.
If both the subquery and the outer table are huge -- either might work as well
as the other -- depends on the indexes and other factors.
for me the difference is that
when using in, it stores a fix size memory
as in
SELECT employeeid FROM emp_table
WHERE employeeid IN
(SELECT bademployee FROM badrecords)
(SELECT bademployee FROM badrecords) will be stored in memory,
well if this is huge, say a million records), then
this query will be slow and takes a lot of memory.
as oppose to
SELECT employeeid FROM emp_table
WHERE employeeid EXIST
(SELECT null FROM badrecords WHERE bademployee = employeeid )
>>? why not? (SELECT bademployee FROM badrecords WHERE bademployee = employeeid )
>>because there is really nothing to select from. so just select null.
this time, instead of returning a millions of records, it will be filter out again
by "WHERE bademployee = employeeid"
this time, the EXIST query will loop through each employeeID from emp_table
and compare it with the result.
now EXIST vs IN?
depends on situation. both have their pros and cons.
both exist cause both have their specialty on above situation.
Business Accounts
Answer for Membership
by: ShweetaPosted on 2005-09-01 at 18:43:59ID: 14807094
IN and EXISTS are both WHERE clauses but whereas IN is a function, WHERE is a condition.
Also, both of these have quite different implementations.
IN is used for matching one field value with a set of values.
This set of values could be literals - string, number etc. or could be result of a subquery.
If, that field value is equal to at least one of the set of values, then the condition is true.
But, when we come to EXISTS, this is always followed by a subquery. If the subquery returns at least one row, the condition is said to be 'met'.
For example,
SELECT columnname
FROM tablename
WHERE column1 IN (value1,value2,value3)
OR
SELECT columns
FROM table1
WHERE column1 IN ( SELECT column1
FROM table2)
The subquery "SELECT column FROM table2" also would be considered as a set of values to match with.
The above two examples will have the condition 'met' if the value of column1 exists in the set of values.
And for EXISTS,
SELECT columns
FROM table1
WHERE EXISTS (SELECT columns
FROM table2
WHERE column1='Somevalue')
The EXISTS condition will be true, when the subquery returns at least one row.
Shweta