📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PostgreSQL Essentials JOINs

JOINs

7 min read Quiz at the end
JOINs combine rows from multiple tables. INNER JOIN returns only matching rows. LEFT JOIN returns all left table rows plus matches from the right. This is how you query data split across multiple related tables.

Joining Tables

-- INNER JOIN (matching rows only)
SELECT u.name, o.total
FROM users u
INNER JOIN orders o ON u.id = o.user_id;

-- LEFT JOIN (all users, even with no orders)
SELECT u.name, o.total
FROM users u
LEFT JOIN orders o ON u.id = o.user_id;

-- Multiple joins
SELECT u.name, p.name AS product, o.total
FROM orders o
JOIN users u ON o.user_id = u.id
JOIN products p ON o.product_id = p.id;
Topic Quiz · 5 questions

Test your understanding before moving on

1. Which JOIN returns only matching rows?
💡 INNER JOIN returns rows that have matches in both tables.
2. Which JOIN returns all rows from the left table?
💡 LEFT JOIN returns all left-table rows, NULLs for unmatched right rows.
3. What does ON specify in a JOIN?
💡 ON specifies the condition that links the two tables.
4. What does a CROSS JOIN produce?
💡 CROSS JOIN produces every combination of rows from both tables.
5. How many tables can you JOIN in one query?
💡 You can JOIN any number of tables in a single SQL query.