What is the difference between in and exists.
Ex: select * from emp where empno in(....) and
select * from emp where empno exists(....)

What is the difference between a Join and Union and Union
and UnionAll.

Answer Posted / nandkumar karlekar

Answer:-

1. Union is heavy as compare to Union All

2. result of Union Query is Set where as result of
Union ALL is not a Set it’s only concatenation of two
results

3. Suppose table1 and table2 have T1 ,T2 records
respectively then the number of comparison require to
produce result is as follows



Union All requires O (1) time complexity

Union Requires O ((T1*(T1+1)/2) + (T2*(T2+1)/2) + (T1 *T2))





Example for UNION: - Table1 has 10 records

Table2 has 20 records

Suppose: table1 and table2 has all record distinct.



Total comparisons require = 465 comparisons



Example for UNION ALL: -

Table1 has 10 records

Table2 has 20 records



Suppose: table1 and table2 has all record distinct or not,
no problem.



Total comparisons require = Constant or may be 0

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does man by sql wildcard characters in sql server?

706


What is primary key index?

704


Define a cross join?

755


What is data mart? : sql server analysis services, ssas

803


List layers of abstraction microsoft architectured to provide relational db through cloud platform ?

175






What command would you use to add a column to a table in sql server?

972


What is the tcp/ip port on which sql server runs?

746


How do database indexes work?

716


What is the difference between left and right outer join?

704


How to rename databases in ms sql server?

814


What structure can you implement for the database to speed up table reads?

939


How to change the data type of an existing column with "alter table" statements in ms sql server?

729


Do you know what is lock escalation?

768


Explain transaction server auto commit?

717


what is the difference between openrowset and openquery?

758