What is the exact difference b/w IN and EXIST in Oracle..?

Answer Posted / moorthy g

select ename from emp e
where mgr in (select empno from emp whereename = 'KING');

Here's the EXPLAIN PLAN for this query:

OBJECT OPERATION
---------- ----------------------------------------
SELECTSTATEMENT()
NESTEDLOOPS()
EMP TABLEACCESS(FULL)
EMP TABLEACCESS(BY INDEX ROWID)
PK_EMP INDEX(UNIQUESCAN)

This query is virtually equivalent to this:

select e1.ename from emp e1,(select empno from empwhere
ename = 'KING') e2
where e1.mgr = e2.empno;

You can write the same query using EXISTS bymoving the outer
query column to a subquery condition, likethis:

select ename from emp e
where exists (select 0 from emp wheree.mgr = empno and
ename = 'KING');

When you write EXISTS in a where clause, you'retelling the
optimizer that you want the outer query to be runfirst,
using each value to fetch a value from the inner
query(think: EXISTS = outside to inside).

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

can anyone explain me about retail domain project in informatica?

7566


How can one identify whether mapping is correct or not without connecting session?

1020


What are connected or unconnected transformations?

721


What is meant by lookup transformation? Explain the types of lookup transformation?

652


What is the way to execute pl/sql script using informatica mapping?

1083






What are the issues you have faced in your project? How did you overcome those issues?

2001


How to start a workflow using pmcmd command?

811


in staging we are merging the data and remove the inconsistants data that type of situation what u will done and type of functions u can use

1751


What are junk dimensions?

705


What are the components of workflow manager?

675


What is informatica?

772


in u flatfile some of fact records are missed then u load the diminision records are not if u load diminsion records what about fact table records

1849


What are the differences between a connected lookup and unconnected lookup?

721


How to handle decimal places while importing a flatfile into informatica?

810


What is status code in informatica?

682