EN
MySQL - JOIN query cases with examples
13 points
In this short article, we would like to show how to built MySQL JOIN queries for different cases.

Visualisation | SQL Query |
---|---|
|
INNER JOIN xxxxxxxxxx 1 SELECT * 2 FROM table_a A 3 JOIN table_b B ON A.key = B.key |
|
LEFT OUTER JOIN xxxxxxxxxx 1 SELECT * 2 FROM table_a A 3 LEFT JOIN table_b B ON A.key = B.key |
|
RIGHT OUTER JOIN xxxxxxxxxx 1 SELECT * 2 FROM table_a A 3 RIGHT JOIN table_b B ON A.key = B.key |
|
FULL OUTER JOIN xxxxxxxxxx 1 SELECT * FROM table_a A 2 LEFT JOIN table_b B ON A.key = B.key 3 UNION 4 SELECT * FROM table_a A 5 RIGHT JOIN table_b B ON A.key = B.key |
|
LEFT OUTER JOIN with exclusion xxxxxxxxxx 1 SELECT * 2 FROM table_a A 3 LEFT JOIN table_b B ON A.key = B.key 4 WHERE B.key IS NULL |
|
RIGHT OUTER JOIN with exclusion xxxxxxxxxx 1 SELECT * 2 FROM table_a A 3 RIGHT JOIN table_b B ON A.key = B.key 4 WHERE A.key IS NULL |
|
FULL OUTER JOIN with exclusion xxxxxxxxxx 1 SELECT * FROM table_a A 2 LEFT JOIN table_b B ON A.key = B.key 3 WHERE B.key IS NULL 4 UNION 5 SELECT * FROM table_a A 6 RIGHT JOIN table_b B ON A.key = B.key 7 WHERE A.key IS NULL |
Alternative titles
- MySQL - difference between inner / outer joins
- MySQL - inner / outer joins explanation
- MySQL - INNER JOIN
- MySQL - LEFT OUTER JOIN
- MySQL - RIGHT OUTER JOIN
- MySQL - FULL OUTER JOIN
- MySQL - LEFT OUTER JOIN with exclusion
- MySQL - RIGHT OUTER JOIN with exclusion
- MySQL - RIGHT OUTER JOIN with exclusion
- MySQL - JOIN list + SQL Query