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:
Step 1: Understand the condition
We want departments where no employee earns 50000 or less.
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.
Final Answer:
SELECT name FROM Departments WHERE dept_id NOT IN (SELECT dept_id FROM Employees WHERE salary <= 50000) -> Option A
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
Master "Subqueries" in SQL
9 interactive learning modes - each teaches the same concept differently