SQL - Inner Join

Overview

INNER JOIN returns rows where the join condition matches in both tables.

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

Prerequisite

Load the Standard Test Data.

Expected Output (live)

first_namedepartment
AdaEngineering
BobEngineering
ChenHR
DeeSales
EliEngineering

Sample Use Cases (3)

1) Employees with department and city

first_namedepartmentcity
AdaEngineeringSan Francisco
BobEngineeringNew York
ChenHRSeattle
DeeSalesAustin
EliEngineeringBoston

2) Orders with customers

order_idcustomerorder_date
1Alice2024-05-01
2Ben2024-05-03
3Cara2024-05-05

3) Order items with products

order_idproductqtyprice
1Laptop Pro11999
1Wireless Mouse149.99
2Office Chair1299
2Coffee Beans114.99
3Standing Desk1499
3Wireless Mouse114.99