// ferramenta gratuita

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

idnomedept_id chave
1Alice10
2Bob20
3Carol30

departments d

dept_id chavedept_name
10Engineering
20Vendas
40Marketing
  • Click a cell to change it. Enter moves down a row, Esc undoes the edit. Nothing is uploaded.
  • Clear a cell or type NULL to make it NULL. A new row stays out of the results until you type in it.
  • The joins match on dept_id, marcada chave in both tables. Carol (30) has no department and Marketing (40) has no one in it, so the outer joins have rows to keep.

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;
employees departments

2 rows

INNER JOIN result
employees edepartments d
e.ide.namee.dept_idd.dept_idd.dept_name
1Alice1010Engineering
2Bob2020Vendas

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;
employees departments

3 rows · 1 unmatched

LEFT JOIN result
employees edepartments d
e.ide.namee.dept_idd.dept_idd.dept_name
1Alice1010Engineering
2Bob2020Vendas
3Carol30NULLNULL

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;
employees departments

3 rows · 1 unmatched

RIGHT JOIN result
employees edepartments d
e.ide.namee.dept_idd.dept_idd.dept_name
1Alice1010Engineering
2Bob2020Vendas
NULLNULLNULL40Marketing

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;
employees departments

4 rows · 2 unmatched

FULL OUTER JOIN result
employees edepartments d
e.ide.namee.dept_idd.dept_idd.dept_name
1Alice1010Engineering
2Bob2020Vendas
3Carol30NULLNULL
NULLNULLNULL40Marketing

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;
employees departments

9 rows

CROSS JOIN result
employees edepartments d
e.ide.namee.dept_idd.dept_idd.dept_name
1Alice1010Engineering
1Alice1020Vendas
1Alice1040Marketing
2Bob2010Engineering
2Bob2020Vendas
2Bob2040Marketing
3Carol3010Engineering
3Carol3020Vendas
3Carol3040Marketing

matched: the key found a partner. kept with NULL on the missing side: the row had no partner in the other table.

Lendo os 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.

// joins are the least of it

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.