Union V/S Join In SQL

Union and Join are both used to combine data from two or more tables. 

The main difference between them is in the way the data is combined.

How Union combines the rows

Union combines the data into new rows like in the pictures. When you use ‘Union’ for combining two tables, then the data of the second table gets added to the first one after the rows of the first table and so on.

Example:

Union combines the rows

 

How JOIN combines the rows

Join combines the data of the columns like below. When you JOIN two tables, the first set of rows shows the first table data and in the same row, the next set data from another table will be reflected.

Example:

JOIN combines the rows

 

Union, Union All, Intersect, Except

Let’s take an example of these 2 tables,

Union, Union All, Intersect, Except

 

So finally, here is the output of different operations.

Union, Union All, Intersect, Except
Next Recommended Reading SQL Server - Union Vs. Union All