Bird
0
0

Consider tables:

medium📝 query result Q5 of 15
SQL - LEFT and RIGHT JOIN
Consider tables:
Products(id, name)
Sales(product_id, quantity)
Query:
SELECT p.name, s.quantity FROM Products p LEFT JOIN Sales s ON p.id = s.product_id WHERE s.quantity > 10;
What will this query return?
ANo rows because WHERE filters out NULLs
BOnly products with sales quantity > 10
CAll products regardless of sales quantity
DAll products with NULL quantity replaced by 0
Step-by-Step Solution
Solution:
  1. Step 1: Analyze WHERE clause effect on LEFT JOIN

    WHERE s.quantity > 10 filters rows after the join. Unmatched products get NULL for quantity.
  2. Step 2: Understand filtering result

    NULL > 10 is false, so unmatched excluded. Only matched rows with quantity > 10 remain: products with sales quantity > 10.
  3. Final Answer:

    Only products with sales quantity > 10 -> Option B
  4. Quick Check:

    WHERE on right table column filters LEFT JOIN to matching rows satisfying condition [OK]
Quick Trick: WHERE on right table column after LEFT JOIN excludes unmatched and non-qualifying rows [OK]
Common Mistakes:
MISTAKES
  • Assuming all left rows appear despite WHERE
  • Thinking NULLs become 0 automatically
  • Confusing WHERE with ON clause filtering

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes