SQL Joins Cheat Sheet
SQL Joins Cheat Sheet
Inner Join
A B
L R
L J R
1 SELECT *
2 FROM A
3 INNER JOIN B ON A.Key = B.Key
Returns rows when there is a match in both tables based on the join condition.
2
Full Join (Full Outer Join)
A B
L R
L J R
1 SELECT *
2 FROM A
3 FULL JOIN B ON A.Key = B.Key
Returns rows when there is a match in either of the tables. It combines the results of
both left and right joins.
3
Full Join Excluding
A B
L R
L J R
1 SELECT *
2 FROM A
3 FULL JOIN B ON A.Key = B.Key
4 WHERE A.Key IS NULL OR B.Key IS NULL
Returns the rows where the keys are NULL in either table A or table B after performing
the full join.
4
Left Join (Left Outer Join)
A B
L R
L J R
1 SELECT *
2 FROM A
3 LEFT JOIN B ON A.Key = B.Key
Returns all rows from the left table and the matched rows from the right table. If there is
no match, NULL values are returned.
5
Left Join Excluding
A B
L R
L J R
1 SELECT *
2 FROM A
3 LEFT JOIN B ON A.Key = B.Key
4 WHERE B.Key IS NULL
Returns all rows from table A where the key does not have a corresponding match in
table B.
6
Right Join (Right Outer Join)
A B
L R
L J R
1 SELECT *
2 FROM A
3 RIGHT JOIN B ON A.Key = B.Key
Returns all rows from the right table and the matched rows from the left table. If there is
no match, NULL values are returned.
7
Right Join Excluding
A B
L R
L J R
1 SELECT *
2 FROM A
3 RIGHT JOIN B ON A.Key = B.Key
4 WHERE B.Key IS NULL
Returns all rows from table B where the key does not have a corresponding match in
table A.