Bird
0
0

You have three tables: sales (1 million rows), products (1000 rows), and categories (50 rows). To optimize a query joining all three, which join order is best for performance?

hard📝 optimization Q15 of 15
SQL - Advanced Joins
You have three tables: sales (1 million rows), products (1000 rows), and categories (50 rows). To optimize a query joining all three, which join order is best for performance?
Options:
A) sales JOIN products JOIN categories
B) products JOIN sales JOIN categories
C) categories JOIN products JOIN sales
D) sales JOIN categories JOIN products
AJoin categories first, then products, then sales.
BJoin products first, then sales, then categories.
CJoin sales first, then products, then categories.
DJoin sales first, then categories, then products.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze table sizes and join order impact

    Joining smaller tables first reduces intermediate result size and speeds up query.
  2. Step 2: Evaluate options based on table sizes

    Categories (50 rows) is smallest, then products (1000 rows), then sales (1 million rows). Joining in order categories -> products -> sales is best.
  3. Final Answer:

    Join categories first, then products, then sales. -> Option A
  4. Quick Check:

    Smallest to largest join order improves speed [OK]
Quick Trick: Join tables from smallest to largest for best speed [OK]
Common Mistakes:
MISTAKES
  • Joining largest table first slows query
  • Ignoring table size in join order
  • Assuming join order doesn't affect performance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes