Repaso
Español

customers LEFT JOIN orders ON ... returns…

Options

  1. Only the customers who have at least one order in the table
  2. All customers; order columns are NULL when there is no order (Correct option)
  3. All orders; customer columns are NULL when a customer is missing
  4. The Cartesian product of both the tables, with all the pairs

Answer

All customers; order columns are NULL for customers without orders

Why

An INNER JOIN keeps only rows that have a match on both sides.

A LEFT JOIN keeps EVERY row from the left table (customers). When a customer has no orders, the order columns are filled with NULL.

Useful for 'show all customers, with their orders if any', or to find customers with no orders: WHERE orders.id IS NULL.

Remember

LEFT JOIN keeps all left rows; missing matches become NULL.

Key terms

Practice this question in Repaso