Bird
0
0

You want to list all employees who have made sales, along with their total sales amount. Which approach is likely more efficient?

hard📝 Application Q8 of 15
SQL - Subqueries
You want to list all employees who have made sales, along with their total sales amount. Which approach is likely more efficient?

Option 1: Use a JOIN between employees and sales and GROUP BY employee.
Option 2: Use a subquery to calculate total sales per employee and join that result to employees.
ABoth options perform the same in all databases.
BOption 2, because subqueries always reduce data early.
COption 2, because JOINs are slower with aggregation.
DOption 1, because JOIN with GROUP BY is optimized for aggregation.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze Option 1

    JOIN with GROUP BY lets the database optimize aggregation directly on joined data.
  2. Step 2: Analyze Option 2

    Subquery aggregation then join may cause extra processing and less optimization.
  3. Final Answer:

    Option 1, because JOIN with GROUP BY is optimized for aggregation. -> Option D
  4. Quick Check:

    JOIN + GROUP BY = efficient aggregation [OK]
Quick Trick: Use JOIN with GROUP BY for aggregation tasks [OK]
Common Mistakes:
MISTAKES
  • Assuming subqueries always reduce data early
  • Ignoring aggregation optimization in JOINs
  • Believing both approaches always perform equally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes