
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 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 that are assigned to a department.
Result:
| ![]() |
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.
Result:
| ![]() |
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.
Result:
| ![]() |
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
.
Result:
| ![]() |
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.
-
Drag the two tables into the canvas
-
Connect them by dragging from one column to the other, to create a foreign key
- Open the Query Builder and cascade related tables
-
Right-click the line to select the JOIN type
-
Choose the columns you want to display
- Run the query and see the results
This is a great way to learn how JOINs work, because DbSchema auto-generates SQL code for you!
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
orFULL 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/