Difference between IN and EXISTS

Answers were Sorted based on User's Feedback



Difference between IN and EXISTS..

Answer / udaykumar

IN - returns a numeric value.
EXIT - returns a boolean value.

Is This Answer Correct ?    7 Yes 2 No

Difference between IN and EXISTS..

Answer / anju saxena

The EXISTS operator tests whether a given set is empty or
not. An exist operator on empty set returns False while on
nonempty set it returns True.
IN operator is used where membership of the element has to
tested against the set.

Is This Answer Correct ?    8 Yes 4 No

Difference between IN and EXISTS..

Answer / 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

Difference between IN and EXISTS..

Answer / yaswanth

IN looks for specified value and
EXISTS looks for whether particular row exists or not

Is This Answer Correct ?    2 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

What is the use of procedures?

0 Answers  


create or replace procedure search_matter(empno varchar2) as sql_stmt varchar2(200); stmt varchar2(200); v_table_name varchar2(200); val_pres number; inp_value varchar2(200); type obj_typ is table of cols.column_name%type index by binary_integer; type all_col is table of varchar2(100) index by binary_integer; typ_obj_typ obj_typ; typ_all_col all_col; begin select object_name bulk collect into typ_obj_typ from user_tables,user_objects where table_name = object_name AND object_type = 'TABLE'; select empno into inp_value from dual; dbms_output.put_line('inp value : '||inp_value); for i in typ_obj_typ.first..typ_obj_typ.last loop v_table_name := NULL; v_table_name := typ_obj_typ(i); dbms_output.put_line(i||':'||typ_obj_typ(i)); dbms_output.put_line('....................'); sql_stmt := 'select column_name from cols where table_name = :1 and data_type in (''CHAR'', ''VARCHAR2'', ''NCHAR'', ''NVARCHAR2'',''NUMBER'')'; EXECUTE IMMEDIATE sql_stmt bulk collect into typ_all_col using typ_obj_typ(i); for inside in typ_all_col.first..typ_all_col.last loop dbms_output.put_line('sql stmt: '||sql_stmt); dbms_output.put_line('column name: '||typ_all_col(inside)||'table name: '||typ_obj_typ(i)); stmt := 'select count(*) from ||typ_obj_typ(i)||'; EXECUTE_IMMEDIATE stmt into val_pres ; if val_pres = 1 then dbms_output.put_line('value present col name: '||typ_all_col(inside)||'table name :'||typ_obj_typ(i)); end if; end loop; dbms_output.put_line('....................'); end loop; exception when others then dbms_output.put_line('sql code '||sqlcode||'Table name: '||v_table_name); dbms_output.put_line('sql message '||sqlerrm); end; Compile-time I am getting below error, Plz help to resolve. LINE/COL ERROR -------- ----------------------------------------------------------------- 47/23 PLS-00103: Encountered the symbol "STMT" when expecting one of the following: := . ( @ % ;

0 Answers  


What is pivot query?

0 Answers  


Can you join a table to itself?

0 Answers  


Does oracle use sql?

0 Answers  






What is sql in oracle?

0 Answers  


Can you call pl/sql package functions from within a fast formula?

0 Answers  


What is the difference between partitioning and sharding?

0 Answers  


What are two parts of package ?

2 Answers   Infosys,


What is optimistic concurrency control? : Transact sql

0 Answers  


What is java sql connection?

0 Answers  


Explain the structure of pl/sql in brief.

0 Answers  


Categories