What are the differences between UNION and JOINS?

Answer Posted / nikhila reddy

UNION:the both tables should have same structure and datatype.
the column name will taken as first table ones it wont bother abt other tables.
example:
emp table as
eid ename esal
1 a 10k
2 b 20k

dept table as
deptid deptname deptsal
11 aa 20k
12 bb 50k


select * from emp
union
select * from dept

empid empname empsal
1 a 10k
2 b 20k
11 aa 20k
12 bb 50k

now u can observe col name taking alias of first table.
no need of relation between a tables.
it will remove duplicate records.


joins:it will join only required fields from different tables.
no need of same structure for tables..
it should have relation between a tables.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to update values in a table with update statements in ms sql server?

563


How to bind a view to the schema of the underlying tables?

593


What are different types of database indexes?

545


Describe in brief sql server monitoring ways.

594


What are the restrictions while creating batches in sql server?

598






What is difference between index seek vs. Index scan?

636


How to defragment indexes with alter index ... Reorganize?

595


Find first and last day of current month in sql server

603


How to get a list all databases on the sql server?

593


What is BCNF? How is it better than 2NF & 3NF?

604


Give an example of SQL injection attack ?

578


What is the process of normalization?

570


What is an identity?

576


What are security principals used in sql server 2005?

523


What is the optimization being performed in oracle and SQL Server?

637