SQL Joins Explained – INNER, LEFT, RIGHT, FULL

When working with databases, your data is often stored in more than one table.
But how can you bring the data together?

This is what SQL JOINs are for.
A JOIN helps you combine rows from two tables based on a related column, usually a column that appe…


This content originally appeared on DEV Community and was authored by Roxana Maria Haidiner

When working with databases, your data is often stored in more than one table.
But how can you bring the data together?

This is what SQL JOINs are for.
A JOIN helps you combine rows from two tables based on a related column, usually a column that appears in both.

Types of SQL JOINs

Here are the most common types of JOINs and what they do:

JOIN Type What it returns
INNER JOIN Only rows that exist in both tables
LEFT JOIN All rows from the left table and matching rows from the right table
RIGHT JOIN All rows from the right table and matching rows from the left table
FULL JOIN All rows from both tables

What Is a SQL JOIN?

Let’s say you have:

  • One table with a list of employees
  • Another table with a list of departments

Each employee works in a department. If we want to know who works where, we need to connect the tables using a JOIN.

The JOIN compares values in both tables and brings the matching rows together.

Example Tables

Table: Employees

employee_id name department_id
1 Sarah James 10
2 Mark White 20
3 Olivia Reed NULL

Table: Departments

department_id department_name
10 Engineering
20 Sales
30 HR

INNER JOIN

Returns only employees who are assigned to a department.

INNER JOIN

SELECT name, department_name
FROM Employees
INNER JOIN Departments
ON Employees.department_id = Departments.department_id;

name department_name
Sarah James Engineering
Mark White Sales

Employees without a department, and departments with no employees, are not shown.

LEFT JOIN

Returns all employees, even if they don’t belong to any department.

LEFT JOIN

SELECT name, department_name
FROM Employees
LEFT JOIN Departments
ON Employees.department_id = Departments.department_id;

name department_name
Sarah James Engineering
Mark White Sales
Olivia Reed NULL

You get all employees.
If they have no department, the result will show NULL.

RIGHT JOIN

Returns all departments, even if no employee is assigned to them.

RIGHT JOIN

SELECT name, department_name
FROM Employees
RIGHT JOIN Departments
ON Employees.department_id = Departments.department_id;

name department_name
Sarah James Engineering
Mark White Sales
NULL HR

You get all departments.
If no one works there, the result shows NULL for the name.

FULL JOIN

Returns all employees and all departments.
If they match, they are shown together.
If not, one side will be NULL.

FULL JOIN

SELECT name, department_name
FROM Employees
FULL JOIN Departments
ON Employees.department_id = Departments.department_id;

name department_name
Sarah James Engineering
Mark White Sales
Olivia Reed NULL
NULL HR

This gives you the full picture.

Summary

  • Use INNER JOIN when you want only matching data
  • Use LEFT JOIN when you want all rows from the first table
  • Use RIGHT JOIN when you want all rows from the second table
  • Use FULL JOIN when you want everything, matched or not

How to Do This Visually in DbSchema

You can use DbSchema to build JOINs without writing any SQL.

  1. Drag the two tables into the canvas

  2. Connect them by dragging from one column to the other, to create a foreign key

Foreign Key in DbSchema

  1. Open the Query Builder and cascade related tables

Query Builder in DbSchema

  1. Right-click the line to select the JOIN type

  2. Choose the columns you want to display

Query Builder in DbSchema

  1. Run the query and see the results

Query Builder in DbSchema

This is a great way to learn how JOINs work, because DbSchema auto-generates SQL code for you!

Query Builder in DbSchema

Note: The JOIN types shown in the menu depend on the database you are connected to.
Some databases (like SQLite) do not support RIGHT JOIN or FULL JOIN.
In these cases, DbSchema will only show the join types supported by your database.

Learn More

If you're learning SQL and want more examples, visit our full SQL Tutorial here:
[https://dbschema.com/blog/tutorials/]


This content originally appeared on DEV Community and was authored by Roxana Maria Haidiner


Print Share Comment Cite Upload Translate Updates
APA

Roxana Maria Haidiner | Sciencx (2025-08-22T19:31:45+00:00) SQL Joins Explained – INNER, LEFT, RIGHT, FULL. Retrieved from https://www.scien.cx/2025/08/22/sql-joins-explained-inner-left-right-full/

MLA
" » SQL Joins Explained – INNER, LEFT, RIGHT, FULL." Roxana Maria Haidiner | Sciencx - Friday August 22, 2025, https://www.scien.cx/2025/08/22/sql-joins-explained-inner-left-right-full/
HARVARD
Roxana Maria Haidiner | Sciencx Friday August 22, 2025 » SQL Joins Explained – INNER, LEFT, RIGHT, FULL., viewed ,<https://www.scien.cx/2025/08/22/sql-joins-explained-inner-left-right-full/>
VANCOUVER
Roxana Maria Haidiner | Sciencx - » SQL Joins Explained – INNER, LEFT, RIGHT, FULL. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/08/22/sql-joins-explained-inner-left-right-full/
CHICAGO
" » SQL Joins Explained – INNER, LEFT, RIGHT, FULL." Roxana Maria Haidiner | Sciencx - Accessed . https://www.scien.cx/2025/08/22/sql-joins-explained-inner-left-right-full/
IEEE
" » SQL Joins Explained – INNER, LEFT, RIGHT, FULL." Roxana Maria Haidiner | Sciencx [Online]. Available: https://www.scien.cx/2025/08/22/sql-joins-explained-inner-left-right-full/. [Accessed: ]
rf:citation
» SQL Joins Explained – INNER, LEFT, RIGHT, FULL | Roxana Maria Haidiner | Sciencx | https://www.scien.cx/2025/08/22/sql-joins-explained-inner-left-right-full/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.