100% found this document useful (1 vote)
199 views8 pages

SQL Joins Cheat Sheet

This document is a cheat sheet for SQL joins, detailing various types including Inner Join, Full Join, Left Join, and Right Join. Each join type is explained with SQL syntax and the conditions under which they return results. The cheat sheet also includes examples of excluding unmatched rows for each join type.

Uploaded by

BlackhosthOne
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
199 views8 pages

SQL Joins Cheat Sheet

This document is a cheat sheet for SQL joins, detailing various types including Inner Join, Full Join, Left Join, and Right Join. Each join type is explained with SQL syntax and the conditions under which they return results. The cheat sheet also includes examples of excluding unmatched rows for each join type.

Uploaded by

BlackhosthOne
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

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.

You might also like