Bird
0
0

What will be the output of this query?

medium📝 query result Q5 of 15
SQL - Subqueries
What will be the output of this query?
SELECT e.name FROM employees e WHERE e.salary > (SELECT MAX(salary) FROM employees WHERE department = e.department);

Assuming salaries vary within departments.
ANo rows, because no salary can be greater than the max in the same department
BEmployees with salary equal to the maximum salary in their department
CAll employees, because the subquery returns NULL
DEmployees with salary greater than the maximum salary in their department
Step-by-Step Solution
Solution:
  1. Step 1: Understand the subquery

    The subquery returns the maximum salary in the employee's department.
  2. Step 2: Compare outer salary with max salary

    No employee can have a salary greater than the maximum salary in their own department.
  3. Final Answer:

    No rows, because no salary can be greater than the max in the same department -> Option A
  4. Quick Check:

    Salary > max salary in department = no rows [OK]
Quick Trick: Salary cannot exceed max salary in same group [OK]
Common Mistakes:
MISTAKES
  • Assuming some rows will match
  • Confusing greater than with equal to
  • Ignoring correlation condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes