Loading Data Driven Insights
Preparing your learning content.
Preparing your learning content.
A beginner-friendly guide to using JOIN inside a SELECT query to read related data from multiple tables in SQL Server.
On this page
Jump to a lesson section
A JOIN is used inside a SELECT query to combine data from two or more related tables.
Instead of storing everything in one large table, databases usually split related information into separate tables. A JOIN helps bring that related information back together when you need to read it.
JOIN connects tables using related columns.
A basic join pattern looks like this.
SELECT
...
FROM Employees AS e
JOIN Departments AS d
ON e.department_id = d.department_id;
In SQL Server, JOIN by itself means INNER JOIN. It returns rows where the join condition matches in both tables.
Imagine you have two separate tables.
The Employees table stores employee details. The Departments table stores department details such as the department name and location.
To show each employee with their department location, SQL needs to connect both tables using a matching column.
employee_id
employee_name
department_id
department_id
department_name
location
We will join the Employees and Departments tables using department_id.
The ON condition tells SQL how the two tables are related.
In this example, Employees.department_id is matched with Departments.department_id.
SELECT
e.employee_name,
d.department_name,
d.location
FROM Employees AS e
INNER JOIN Departments AS d
ON e.department_id = d.department_id;
The ON condition tells SQL how the tables are related.
The result can now show employee information together with department information.
Use JOIN when the information you need is stored across separate but connected tables.
SQL Roadmap Progress
Topic 19 of 111
17% complete
Next in SQL Roadmap
Continue with the next SQL topic in the recommended roadmap order.
Continue learning →