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 can I check that whether automatic statistic update is enabled or not?

788


What is the order by used for?

794


How you would rewrite the sql query to return the customerid sorted numerically?

762


What is clustered vs nonclustered index?

690


Explain the properties of a relational table?

760






Data table as parameter in sql server?

723


When would you use an insert into .. Select option versus an insert into .. Values option? Give an example of each?

862


How you trouble shoot when any job fails

1679


What happens if date-only values are provided as date and time literals?

753


What do you understand by physical_only option in dbcc checkdb?

749


What are the types of joins in sql?

780


How do you rebuild an identity column?

716


Explain how does the report manager work in ssrs?

707


What are the Advantages of using CTE in sql server?

773


What is the current limitation of the size of SQL Azure DB?

120