Joins allow you to combine records from two or more tables based on a shared foreign key relationship.
-- Fetch all users alongside their orders (even if they have none)
SELECT users.username, orders.order_date, orders.total_amount
FROM users
LEFT JOIN orders ON users.id = orders.user_id;
0 Comments