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 is the difference between varchar and varchar(max) datatypes?

563


How do I schedule a sql server profiler trace?

540


What is the difference between clustered and a non-clustered index?

597


Tell me what is difference between clustered and non clustered index?

560


What is a full text index?

497






What is sql stored procedure?

601


What is the standby server?

523


What is the difference between writing data to mirrored drives versus raid5 drives

515


What is the difference between migration and upgradation in sql server?

610


What is row_number()?

586


is there a column to which a default can't be bound? : Sql server database administration

541


How to write character string constants or literals in ms sql server?

549


Explain rdbms?

607


Explain full-text query in sql server?

542


How do we Backup SQL Azure Data?

86