Skip to content

Instantly share code, notes, and snippets.

@sambostock
Created March 20, 2015 08:02
Show Gist options
  • Save sambostock/86d0da9613f41996b2f5 to your computer and use it in GitHub Desktop.
Save sambostock/86d0da9613f41996b2f5 to your computer and use it in GitHub Desktop.
SQL Join Cheatsheet
(-----A-----(-----) B )
SELECT <columns>
FROM table_A A
LEFT JOIN table_B B
ON A.key = B.key
(-----A-----( ) B )
SELECT <columns>
FROM table_A A
LEFT JOIN table_B B
ON A.key = B.key
WHERE B.key IS NULL
( A (-----) B )
SELECT <columns>
FROM table_A A
INNER JOIN table_B B
ON A.key = B.key
(-----A-----(-----)-----B-----)
SELECT <columns>
FROM table_A A
FULL OUTER JOIN table_B B
ON A.key = B.key
(-----A-----( )-----B-----)
SELECT <columns>
FROM table_A A
FULL OUTER JOIN table_B B
ON A.key = B.key
WHERE A.key IS NULL
OR B.key IS NULL
( A (-----)-----B-----)
SELECT <columns>
FROM table_A A
RIGHT JOIN table_B B
ON A.key = B.key
( A ( )-----B-----)
SELECT <columns>
FROM table_A A
RIGHT JOIN table_B B
ON A.key = B.key
WHERE A.key IS NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment