Back

JOINs

JOINs combine data from multiple tables. The most common is INNER JOIN: it returns rows where there's a match in both tables.

-- Tables: users and orders
-- Each order has a user_id

-- INNER JOIN: only matching rows
SELECT users.name, orders.total
FROM users
INNER JOIN orders ON users.id = orders.user_id;

-- LEFT JOIN: all users, even without orders
SELECT users.name, orders.total
FROM users
LEFT JOIN orders ON users.id = orders.user_id;

Roadmap