Bird
0
0

Consider two tables: employees (5000 rows) and departments (50 rows). Which join order will likely reduce query execution time?

medium📝 query result Q5 of 15
SQL - Advanced Joins
Consider two tables: employees (5000 rows) and departments (50 rows). Which join order will likely reduce query execution time?

Query A: SELECT * FROM employees JOIN departments ON employees.dept_id = departments.id;
Query B: SELECT * FROM departments JOIN employees ON employees.dept_id = departments.id;
AQuery B is faster because it starts with the smaller table
BBoth queries will fail due to join condition errors
CBoth queries run equally fast
DQuery A is faster because it starts with the larger table
Step-by-Step Solution
Solution:
  1. Step 1: Understand join order effect

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

    Query A starts with employees (5000 rows), Query B starts with departments (50 rows). Query B is more efficient.
  3. Final Answer:

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

    Small table first improves speed [OK]
Quick Trick: Start joins with smaller tables for efficiency [OK]
Common Mistakes:
MISTAKES
  • Assuming larger table first is always better
  • Ignoring join condition correctness
  • Confusing query failure with performance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes