Skip to content
Related Articles

Related Articles

Improve Article
Difference between JOIN and UNION in SQL
  • Last Updated : 03 May, 2020

JOIN:
JOIN in SQL is used to combine data from many tables based on a matched condition between them. The data combined using JOIN statement results into new columns.

Consider the two tables:

Boys

Girls



Example:

sql> 
SELECT Boys.Name, Boys.Age, Girls.Address,
FROM Boys 
INNER JOIN Girls 
ON Boys.Rollno = Girls.Rollno; 

The resultant table is:

UNION:
UNION in SQL is used to combine the result-set of two or more SELECT statements. The data combined using UNION statement is into results into new distinct rows.

Example:

sql> 
SELECT Name 
FROM Boys 
WHERE Rollno < 16 

UNION

SELECT Name 
FROM Girls 
WHERE Rollno > 9 

The resultant table is:

Difference between JOIN and UNION in SQL :

JOINUNION
JOIN combines data from many tables based on a matched condition between them.SQL combines the result-set of two or more SELECT statements.
It combines data into new columns.It combines data into new rows
Number of columns selected from each table may not be same.Number of columns selected from each table should be same.
Datatypes of corresponding columns selected from each table can be different.Datatypes of corresponding columns selected from each table should be same.
It may not return distinct columns.It returns distinct rows.

Attention reader! Don’t stop learning now. Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :