Bird
0
0

What is wrong with this query if we want to list all customers and their orders, including customers with no orders?

medium📝 Debug Q14 of 15
SQL - LEFT and RIGHT JOIN
What is wrong with this query if we want to list all customers and their orders, including customers with no orders?
SELECT c.name, o.order_id FROM Customers c INNER JOIN Orders o ON c.id = o.customer_id;
AINNER JOIN excludes customers without orders; should use LEFT OUTER JOIN
BThe ON clause is missing
CThe SELECT statement is missing table aliases
DOrders table should be first in the FROM clause
Step-by-Step Solution
Solution:
  1. Step 1: Understand INNER JOIN behavior

    INNER JOIN returns only rows with matching keys in both tables, so customers without orders are excluded.
  2. Step 2: Identify correct join for including all customers

    LEFT OUTER JOIN keeps all customers even if no matching orders exist, showing NULL for order columns.
  3. Final Answer:

    INNER JOIN excludes customers without orders; should use LEFT OUTER JOIN -> Option A
  4. Quick Check:

    Use LEFT OUTER JOIN to include all left table rows [OK]
Quick Trick: Use LEFT OUTER JOIN to include unmatched left table rows [OK]
Common Mistakes:
MISTAKES
  • Using INNER JOIN when outer join is needed
  • Forgetting ON clause (though present here)
  • Thinking table order in FROM matters for join type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes