Bird
0
0

You have three tables: orders (10000 rows), customers (100 rows), and regions (10 rows). To optimize performance, which join order is best for:

hard📝 Application Q8 of 15
SQL - Advanced Joins
You have three tables: orders (10000 rows), customers (100 rows), and regions (10 rows). To optimize performance, which join order is best for:
SELECT * FROM orders JOIN customers ON orders.cust_id = customers.id JOIN regions ON customers.region_id = regions.id;
AJoin regions to customers first, then join orders
BJoin customers to orders first, then regions
CJoin regions to orders first, then customers
DJoin orders to customers first, then join regions
Step-by-Step Solution
Solution:
  1. Step 1: Analyze table sizes and join order

    Orders is largest, customers medium, regions smallest. Joining orders to customers first reduces rows early.
  2. Step 2: Join regions last

    Joining regions last (smallest) after customers reduces join complexity and improves performance.
  3. Final Answer:

    Join orders to customers first, then join regions -> Option D
  4. Quick Check:

    Join large to medium first, then small [OK]
Quick Trick: Join largest tables first, smallest last for best speed [OK]
Common Mistakes:
MISTAKES
  • Joining smallest tables first causing repeated scans
  • Joining unrelated tables first
  • Ignoring table size in join order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes