Bird
0
0

How can you find departments where every employee earns more than 50000 using nested subqueries?

hard📝 Application Q9 of 15
SQL - Subqueries
How can you find departments where every employee earns more than 50000 using nested subqueries?
ASELECT name FROM Departments WHERE dept_id NOT IN (SELECT dept_id FROM Employees WHERE salary <= 50000)
BSELECT name FROM Departments WHERE dept_id IN (SELECT dept_id FROM Employees WHERE salary > 50000)
CSELECT name FROM Departments WHERE dept_id = (SELECT dept_id FROM Employees WHERE salary > 50000)
DSELECT name FROM Departments WHERE dept_id NOT IN (SELECT dept_id FROM Employees WHERE salary > 50000)
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition

    We want departments where no employee earns 50000 or less.
  2. Step 2: Analyze the query logic

    SELECT name FROM Departments WHERE dept_id NOT IN (SELECT dept_id FROM Employees WHERE salary <= 50000) excludes departments that have any employee earning 50000 or less by using NOT IN with a subquery.
  3. Final Answer:

    SELECT name FROM Departments WHERE dept_id NOT IN (SELECT dept_id FROM Employees WHERE salary <= 50000) -> Option A
  4. Quick Check:

    NOT IN excludes departments with low earners [OK]
Quick Trick: Use NOT IN to exclude unwanted groups [OK]
Common Mistakes:
MISTAKES
  • Using IN instead of NOT IN
  • Assuming = works with multiple rows
  • Ignoring employees with salary <= 50000

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes