JOIN overview

JOIN combines rows from two or more tables. The examples below show matching rows and unmatched rows for the main join types.

LEFT JOIN

Query

Matching rows

SELECT select_list FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key

LEFT JOIN

SELECT select_list FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key WHERE B.Key IS NULL

Unmatched left rows

RIGHT JOIN

Query

Matching rows

SELECT select_list FROM TableA A RIGHT JOIN TableB B ON A.Key = B.Key

RIGHT JOIN

SELECT select_list FROM TableA A RIGHT JOIN TableB B ON A.Key = B.Key WHERE A.Key IS NULL

Unmatched right rows

INNER JOIN

Query

Matching rows

SELECT select_list FROM TableA A INNER JOIN TableB B ON A.Key = B.Key

INNER JOIN

FULL JOIN

Query

Matching rows

SELECT select_list FROM TableA A FULL OUTER JOIN TableB B ON A.Key = B.Key

FULL JOIN

SELECT select_list FROM TableA A FULL OUTER JOIN TableB B ON A.Key = B.Key WHERE A.Key IS NULL OR B.Key IS NULL

Unmatched rows from both tables

Last updated on