Difference between JOIN and UNION in SQL

JOINs are used to retrieve data from two or more tables (Combine rows from multiple tables) based on logical relationships between the tables.

Note: There are 4 types of joins available in MS SQL Server. They are INNER JOIN, LEFT OUTER JOIN, RIGHT OUTER JOIN, FULL OUTER JOIN.


SELECT tbl1.Column1, tbl2.Column2 FROM Table1 tbl1 JOIN Table2 tbl2 ON tbl1.RelColumn = tbl2.RelColumn

UNION is used to combine multiple result sets into single result set. Each select statement which are using UNION must have the same number of columns in same order with compatible (similar) data types.

Note: By default UNION will return distinct records, to include duplicate values use UNION ALL.


SELECT City, State FROM tblCustomer UNION SELECT City, State FROM tblVendor