Bird
0
0

Given tables products (10000 rows) and categories (10 rows), which join order is likely to run faster?

medium📝 query result Q4 of 15
SQL - Advanced Joins
Given tables products (10000 rows) and categories (10 rows), which join order is likely to run faster?

Query 1: SELECT * FROM products JOIN categories ON products.cat_id = categories.id;
Query 2: SELECT * FROM categories JOIN products ON products.cat_id = categories.id;
AQuery 1 is faster because it starts with the large table
BQuery 2 is faster because it starts with the small table
CBoth queries have the same performance
DNeither query will run due to syntax errors
Step-by-Step Solution
Solution:
  1. Step 1: Analyze join order impact

    Starting with the large table allows filtering early and reduces rows processed in join.
  2. Step 2: Compare queries

    Query 1 starts with products (large), Query 2 starts with categories (small). Query 1 is more efficient.
  3. Final Answer:

    Query 1 is faster because it starts with the large table -> Option A
  4. Quick Check:

    Large table first improves performance [OK]
Quick Trick: Join large tables first to improve speed [OK]
Common Mistakes:
MISTAKES
  • Assuming small table first is always faster
  • Ignoring table size in join order
  • Confusing syntax errors with performance issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes