JOINs are the foundation of relational SQL. Without them, you'd need multiple queries to combine data from different tables. This guide explains every JOIN type clearly, with examples you can run in the SQLab playground.
Returns only rows where there is a match in BOTH tables. Rows with no match in either table are excluded.
SELECT u.first_name, o.total, o.status FROM users u INNER JOIN orders o ON o.user_id = u.id LIMIT 10; -- Only users WHO HAVE orders are returned.
Returns ALL rows from the left table, and matching rows from the right. If no match exists, right-table columns are NULL. Essential when you want to include records even without related data.
SELECT u.first_name, COUNT(o.id) AS order_count FROM users u LEFT JOIN orders o ON o.user_id = u.id GROUP BY u.id ORDER BY order_count DESC; -- All users appear, even those with 0 orders.
SELECT u.first_name, p.name AS product, oi.quantity FROM users u JOIN orders o ON o.user_id = u.id JOIN order_items oi ON oi.order_id = o.id JOIN products p ON p.id = oi.product_id LIMIT 20;
Always use table aliases (u, o, p) when joining multiple tables. Always specify the JOIN condition in ON — never use implicit comma joins (FROM a, b WHERE a.id = b.id is old syntax and error-prone).
Run all the queries from this article in our free SQL playground.
Open SQL Playground →