Bird
0
0

Given tables orders (1000 rows) and customers (10 rows), which join order is likely faster?

medium📝 query result Q13 of 15
SQL - Advanced Joins
Given tables orders (1000 rows) and customers (10 rows), which join order is likely faster?
Query 1: SELECT * FROM orders JOIN customers ON orders.customer_id = customers.id;
Query 2: SELECT * FROM customers JOIN orders ON customers.id = orders.customer_id;
AQuery 1 is faster because orders is first.
BQuery 2 is faster because customers is first and smaller.
CBoth queries have the same speed always.
DQuery 2 will cause an error due to join order.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze table sizes and join order

    Joining smaller tables first often helps performance because fewer rows are processed early.
  2. Step 2: Compare queries

    Query 2 starts with the smaller customers table (10 rows), likely reducing intermediate data size and speeding up join.
  3. Final Answer:

    Query 2 is faster because customers is first and smaller. -> Option B
  4. Quick Check:

    Smaller table first improves speed [OK]
Quick Trick: Join smaller tables first for better speed [OK]
Common Mistakes:
MISTAKES
  • Assuming join order never affects speed
  • Thinking larger table first is always better
  • Believing join order causes errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes