Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Difference between IN and EXISTS

Answer Posted / subathra

IN: Inner query executes first and drives the outer query.
EXISTS: Outer query executes first and compares tge rows
retrived with the inner query.
Consider table tab1 has 1000 rows and table tab2 has 1000
rows.
IN: select t1.empid from tab1 t1 where t1.code in (select
t2.code from tab2 t2) -- All rows in t1 will read with t2
and the effect is 1000 X 1000 rows.
EXISTS: select t1.empid from tab1 t1 where exists (select 1
from tab2 t2 where t1.code=t2.code) -- Max of 1 row will be
read for each row of t1 and thus reduces the processing
overhead.
Thumb rule:
1) If the majority of the filtering are in the sub query
then use IN.
1) If the majority of the filtering are in the outer query
then use EXISTS.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How would you pass hints to the sql processor?

983


What is output spooling in sql*plus?

1039


What sql does db2 use?

984


Is it possible to include an insert statement on the same table to which the trigger is assigned?

1022


What is crud sql?

990


What is the difference between delete, truncate and drop command?

1155


What is the difference between delete and truncate statement in sql?

1075


How to change a value of the field ‘salary’ as 7500 for an employee_name ‘john’ in a table employee_details?

1439


How can we implement rollback or commit statement in a trigger?

1041


List the different type of joins?

1061


What do you understand by exception handling in pl/sql?

1035


Does view contain data?

1039


what does the t-sql command ident_incr does? : Transact sql

1081


How many times can we commit in a loop?

1023


What is procedure function?

1066