SQL JOIN visualizer
Joins are easy to read and easy to misread. Pick one of five join types and see its SQL, its diagram and the exact rows it returns from two small tables. Change a value in either table and the result changes next to it.
Try the joins
employees e
| id | name | dept_id clave |
|---|---|---|
| 1 | Alice | 10 |
| 2 | Bob | 20 |
| 3 | Carol | 30 |
departments d
| dept_id clave | dept_name |
|---|---|
| 10 | Engineering |
| 20 | Ventas |
| 40 | Marketing |
- Click a cell to change it. Enter moves down a row, Esc undoes the edit. Nothing is uploaded.
- Clear a cell or type
NULLto make it NULL. A new row stays out of the results until you type in it. - The joins match on
dept_id, marcada clave in both tables. Carol (30) has no department and Marketing (40) has no one in it, so the outer joins have rows to keep.
| employees e | departments d | |||
|---|---|---|---|---|
| e.id | e.name | e.dept_id | d.dept_id | d.dept_name |
How each JOIN works
Each section shows the shape of the join, its SQL and the rows it returns for the tables
above, and updates as you edit them. When a row has no match in the other table, an outer
join keeps it and fills the missing side with NULL: those are the shaded rows.
INNER JOIN: only the matches #
Keeps only the rows where the key matches in both tables. Alice and Bob belong to departments that exist; Carol and Marketing never appear.
SELECT e.id, e.name, e.dept_id, d.dept_id, d.dept_name FROM employees e INNER JOIN departments d ON e.dept_id = d.dept_id;
2 rows
| employees e | departments d | |||
|---|---|---|---|---|
| e.id | e.name | e.dept_id | d.dept_id | d.dept_name |
| 1 | Alice | 10 | 10 | Engineering |
| 2 | Bob | 20 | 20 | Ventas |
LEFT JOIN: all of the left table, matches from the right #
Keeps every row from the left table. When the right table has no match, its columns come back as NULL. Carol shows up with no department.
SELECT e.id, e.name, e.dept_id, d.dept_id, d.dept_name FROM employees e LEFT JOIN departments d ON e.dept_id = d.dept_id;
3 rows · 1 unmatched
| employees e | departments d | |||
|---|---|---|---|---|
| e.id | e.name | e.dept_id | d.dept_id | d.dept_name |
| 1 | Alice | 10 | 10 | Engineering |
| 2 | Bob | 20 | 20 | Ventas |
| 3 | Carol | 30 | NULL | NULL |
RIGHT JOIN: the mirror image #
The mirror of LEFT JOIN: keeps every row from the right table, with NULLs where the left table has no match. Marketing stays in although nobody works there. Its e.dept_id is NULL because that column comes from the missing side; only d.dept_id holds 40.
SELECT e.id, e.name, e.dept_id, d.dept_id, d.dept_name FROM employees e RIGHT JOIN departments d ON e.dept_id = d.dept_id;
3 rows · 1 unmatched
| employees e | departments d | |||
|---|---|---|---|---|
| e.id | e.name | e.dept_id | d.dept_id | d.dept_name |
| 1 | Alice | 10 | 10 | Engineering |
| 2 | Bob | 20 | 20 | Ventas |
| NULL | NULL | NULL | 40 | Marketing |
FULL OUTER JOIN: nothing dropped #
The inner join plus the unmatched rows from both sides, with NULL on whichever side is missing. Carol and Marketing both appear. MySQL and MariaDB have no FULL OUTER JOIN; there you write a LEFT JOIN, then UNION ALL the RIGHT JOIN rows where e.dept_id IS NULL.
SELECT e.id, e.name, e.dept_id, d.dept_id, d.dept_name FROM employees e FULL OUTER JOIN departments d ON e.dept_id = d.dept_id;
4 rows · 2 unmatched
| employees e | departments d | |||
|---|---|---|---|---|
| e.id | e.name | e.dept_id | d.dept_id | d.dept_name |
| 1 | Alice | 10 | 10 | Engineering |
| 2 | Bob | 20 | 20 | Ventas |
| 3 | Carol | 30 | NULL | NULL |
| NULL | NULL | NULL | 40 | Marketing |
CROSS JOIN: every combination #
Every row of one table paired with every row of the other, with no matching at all: 3 employees times 3 departments is 9 rows (the cartesian product). Carol gets all three departments even though her key matches none of them.
SELECT e.id, e.name, e.dept_id, d.dept_id, d.dept_name FROM employees e CROSS JOIN departments d;
9 rows
| employees e | departments d | |||
|---|---|---|---|---|
| e.id | e.name | e.dept_id | d.dept_id | d.dept_name |
| 1 | Alice | 10 | 10 | Engineering |
| 1 | Alice | 10 | 20 | Ventas |
| 1 | Alice | 10 | 40 | Marketing |
| 2 | Bob | 20 | 10 | Engineering |
| 2 | Bob | 20 | 20 | Ventas |
| 2 | Bob | 20 | 40 | Marketing |
| 3 | Carol | 30 | 10 | Engineering |
| 3 | Carol | 30 | 20 | Ventas |
| 3 | Carol | 30 | 40 | Marketing |
matched: the key found a partner.
kept with NULL on the missing
side: the row had no partner in the other table.
Leyendo los resultados
- Duplicate matches multiply. If two right rows share a key, a left row that matches comes back once per match. Change Marketing's key to 10 and Alice comes back twice.
- NULL keys never match. A NULL in either key column matches nothing, not even another NULL: SQL treats NULL as unknown, so NULL = NULL is not true. Clear Bob's key and he drops out of INNER and RIGHT, LEFT and FULL keep him with NULLs, and Sales becomes an unmatched row.
- Number-like keys compare as numbers. Here, as in an INT column, 10 matches 10.0. Any other key compares as exact, case-sensitive text.
- OUTER is optional. LEFT JOIN and LEFT OUTER JOIN are the same join, as are FULL JOIN and FULL OUTER JOIN.
- Engine support varies. SQL Server, PostgreSQL and Oracle run all five joins. MySQL and MariaDB support RIGHT JOIN but not FULL OUTER JOIN. SQLite added RIGHT and FULL joins in 3.39.0 (June 2022).
SQL JOIN FAQ
Is this SQL JOIN visualizer free?
Yes. There is no sign-up and no usage limit, the same as the other SQLly web tools.
Is the data in the sample tables sent anywhere?
No. Your browser computes the joins as you edit, so nothing leaves your device. Once the page has loaded, it keeps working without a connection for as long as the tab stays open.
What is the difference between LEFT JOIN and LEFT OUTER JOIN?
Nothing. The OUTER keyword is optional: LEFT JOIN and LEFT OUTER JOIN are the same operation in every engine that supports them. The same goes for RIGHT JOIN and RIGHT OUTER JOIN, and for FULL JOIN and FULL OUTER JOIN.
Why does an unmatched row show NULL?
An outer join keeps the row from one table even when the other table has no match, and fills the missing side with NULL. That is how a LEFT JOIN can return a customer with no orders: the order columns come back as NULL.
How is FULL OUTER JOIN different from LEFT JOIN plus RIGHT JOIN?
A FULL OUTER JOIN keeps each matched row once and adds the unmatched rows from both sides. That equals a LEFT JOIN, UNION ALL only the unmatched rows of the RIGHT JOIN, so no match is listed twice.
What does a CROSS JOIN return?
Every combination of rows: m rows times n rows. With no ON condition there is nothing to match on, so a 3-row table joined to a 4-row table returns 12 rows. Add a WHERE clause that compares the keys and you get the inner join's rows back.
Does MySQL support FULL OUTER JOIN?
No. MySQL (and MariaDB) support INNER, LEFT, RIGHT and CROSS JOIN but not FULL OUTER JOIN. The usual workaround is a LEFT JOIN, then UNION ALL a RIGHT JOIN filtered to the rows where the left table's key IS NULL, which adds back only the unmatched right rows.
Does SQLite support RIGHT JOIN and FULL JOIN?
Yes, since SQLite 3.39.0 (June 2022). Earlier versions only supported INNER, LEFT and CROSS JOIN, which is why older tutorials warn against RIGHT JOIN in SQLite.
Related on SQLly
- SQL joins interview questions Interview questions
- Excluding rows: NOT IN vs NOT EXISTS vs LEFT JOIN Dialect comparison
- UPDATE with a join to another table Dialect comparison
- DELETE rows matched in another table Dialect comparison
- Full outer compare of two result sets Snippet
- Join child rows into a comma-separated list in SQL Snippet
Run these joins on your own data
SQLly is a native SQL workbench for macOS, Windows and Linux. Query SQL Server, PostgreSQL, MySQL, SQLite and more, with IntelliSense that knows your schema.