Intermediate · Lesson 10 of 20

Combining Tables with INNER JOIN

INNER JOIN combines rows from two tables based on a matching condition.

It only returns rows where there is a match in BOTH tables.

SELECT e.first_name, d.name AS department_name
FROM employees e
INNER JOIN departments d
ON e.department_id = d.id;

Key concepts:

  • Use aliases (e, d) to shorten table names
  • ON specifies the matching condition
  • Only matching rows appear in results
  • Employees without a department are excluded

INNER JOIN is the most common type of join in SQL.

Check your understanding

Get each employee's name with their department name using INNER JOIN.

Examples run on the employees sample database. Open any of them in the playground to experiment.