Bird
0
0

You want to list all customers and their orders, but also show customers with no orders. Which query correctly preserves all customers even if they have no orders?

hard📝 Application Q8 of 15
SQL - LEFT and RIGHT JOIN
You want to list all customers and their orders, but also show customers with no orders. Which query correctly preserves all customers even if they have no orders?
ASELECT Customers.name, Orders.id FROM Orders LEFT JOIN Customers ON Customers.id = Orders.customer_id;
BSELECT Customers.name, Orders.id FROM Customers LEFT JOIN Orders ON Customers.id = Orders.customer_id;
CSELECT Customers.name, Orders.id FROM Customers INNER JOIN Orders ON Customers.id = Orders.customer_id;
DSELECT Customers.name, Orders.id FROM Customers RIGHT JOIN Orders ON Customers.id = Orders.customer_id;
Step-by-Step Solution
Solution:
  1. Step 1: Identify which table to preserve

    We want all customers, so Customers is the left table.
  2. Step 2: Choose correct JOIN type and order

    LEFT JOIN preserves all left rows; SELECT Customers.name, Orders.id FROM Customers LEFT JOIN Orders ON Customers.id = Orders.customer_id; uses LEFT JOIN with Customers as left table.
  3. Final Answer:

    SELECT Customers.name, Orders.id FROM Customers LEFT JOIN Orders ON Customers.id = Orders.customer_id; -> Option B
  4. Quick Check:

    LEFT JOIN with Customers left preserves all customers [OK]
Quick Trick: LEFT JOIN left_table preserves all left rows even if no match [OK]
Common Mistakes:
MISTAKES
  • Using INNER JOIN excludes customers without orders
  • Reversing table order in JOIN
  • Using RIGHT JOIN when LEFT JOIN is needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes