Lesson 7 of 9
JOINs
JOIN combines data from two or more tables. INNER JOIN returns only matching rows. LEFT JOIN returns all rows from the left table and matching rows from the right.
SQL
-- Inner Join: users who have orders
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;