Languages
[Edit]
EN

MySQL - JOIN query cases with examples

13 points
Created by:
WGates
412

In this short article, we would like to show how to built MySQL JOIN queries for different cases.

Possible JOIN cases in MySQL.
Possible JOIN cases in MySQL.
VisualisationSQL Query

INNER JOIN in MySQL

INNER JOIN

SELECT *
FROM table_a A
JOIN table_b B ON A.key = B.key

LEFT OUTER JOIN in MySQL

LEFT OUTER JOIN

SELECT *
FROM table_a A
LEFT JOIN table_b B ON A.key = B.key

RIGHT OUTER JOIN in MySQL

RIGHT OUTER JOIN

SELECT *       
FROM table_a A
RIGHT JOIN table_b B ON A.key = B.key

FULL OUTER JOIN in MySQL

FULL OUTER JOIN

SELECT * FROM table_a A
LEFT JOIN table_b B ON A.key = B.key
UNION
SELECT * FROM table_a A
RIGHT JOIN table_b B ON A.key = B.key

LEFT OUTER JOIN with exclusion in MySQL

LEFT OUTER JOIN with exclusion

SELECT  *
FROM table_a A
LEFT JOIN table_b B ON A.key = B.key
WHERE B.key IS NULL

RIGHT OUTER JOIN with exclusion in MySQL

RIGHT OUTER JOIN with exclusion

SELECT *
FROM table_a A
RIGHT JOIN table_b B ON A.key = B.key
WHERE A.key IS NULL

FULL OUTER JOIN with exclusion in MySQL

FULL OUTER JOIN with exclusion

SELECT * FROM table_a A
LEFT JOIN table_b B ON A.key = B.key
WHERE B.key IS NULL 
UNION
SELECT * FROM table_a A
RIGHT JOIN table_b B ON A.key = B.key
WHERE A.key IS NULL

Alternative titles

  1. MySQL - difference between inner / outer joins
  2. MySQL - inner / outer joins explanation
  3. MySQL - INNER JOIN
  4. MySQL - LEFT OUTER JOIN
  5. MySQL - RIGHT OUTER JOIN
  6. MySQL - FULL OUTER JOIN
  7. MySQL - LEFT OUTER JOIN with exclusion
  8. MySQL - RIGHT OUTER JOIN with exclusion
  9. MySQL - RIGHT OUTER JOIN with exclusion
  10. MySQL - JOIN list + SQL Query
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - JOIN list + SQL Query

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join