LEFT JOIN keeps every row from the left table, even without a match.
LEFT JOIN keeps every row from the left table, even without a match. Read the query line by line and identify the input table, the transformation, and the shape of the result before running it.
SELECT c.name, o.order_id FROM customers c LEFT JOIN orders o ON o.customer_id = c.customer_id ORDER BY c.customer_id, o.order_id;
Before running the example, predict the output columns and whether the query returns one row, many rows, or possibly no rows.
In your own words, explain the main SQL feature in today’s lesson and why it answers the question.
Recall prompt: Start with customers and LEFT JOIN orders. Close this page section mentally and explain the query from memory before proceeding.
List all customers and any orders they have, including customers with no orders.
Start with customers and LEFT JOIN orders.