Bird
0
0

What will be the output of this query?

medium📝 query result Q13 of 15
PostgreSQL - Subqueries in PostgreSQL
What will be the output of this query?
SELECT name FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
ASyntax error due to subquery
BNames of employees earning less than the average salary
CAll employee names
DNames of employees earning more than the average salary
Step-by-Step Solution
Solution:
  1. Step 1: Understand the subquery

    The subquery (SELECT AVG(salary) FROM employees) calculates the average salary of all employees.
  2. Step 2: Apply the condition in the main query

    The main query selects employee names where their salary is greater than this average.
  3. Final Answer:

    Names of employees earning more than the average salary -> Option D
  4. Quick Check:

    Subquery returns average; main query filters salaries above it [OK]
Quick Trick: Subqueries can return single values to compare in main query [OK]
Common Mistakes:
  • Thinking it returns employees below average
  • Assuming syntax error due to subquery
  • Confusing AVG with SUM

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes