Introduction to JOIN
Order only stores a user_id, not the user's name or email. That keeps user data in one place.
JOIN reunites split tables by matching a foreign key back to its row.
Order rows alone
Order only carries user_id — no name, no email.
Loaded Database:introduction-to-join.database-init
SELECT * FROM "Order";Loading plan...Combine with JOIN
JOIN matches Order.user_id to User.id, pulling both tables into one result.
Loaded Database:introduction-to-join.database-init
SELECT "Order".id, "User".name, "Order".amount
FROM "Order"
JOIN "User" ON "User".id = "Order".user_id
ORDER BY "Order".id;Loading plan...What We Learned
- JOINcombines rows from two relations by matching column values.
- Foreign keya column referencing another table's primary key.
- ON clausetells PostgreSQL which columns from each side must match.