Find Salaries Higher Than Any HR Salary
Apply ANY semantics to the HR salary subquery and return the qualifying employees.
- Subqueries
- Filtering
- Sorting
Exercise brief
Understand the request
Compensation benchmarking analyst A benchmark report needs employees paid above at least one salary in HR.
Find every employee (in any department) whose salary exceeds at least one HR (department_id = 20) salary. `> ANY` means `> MIN(...)`. Return employee_id, first_name, last_name, salary — ordered by salary DESC, employee_id.
Return
- Return employee_id, first_name, last_name, salary in this exact left-to-right order.
Constraints
- Use > ANY (SELECT ...) on engines that support quantified predicates.
- On Core SQL, use the equivalent > (SELECT MIN(...)) form.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
employees
employee_idINTEGERfirst_nameVARCHAR(50)last_nameVARCHAR(50)salaryINTEGERdepartment_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
`> ANY (subquery)` ≡ `> MIN(subquery)`. The condition holds when ONE element is beaten.
Hint 2
SOME is a synonym for ANY in standard SQL (PostgreSQL, MySQL, SQL Server). SQLite does NOT support ANY/SOME/ALL.
Hint 3
Empty subquery: `> ANY (∅)` is FALSE — no rows qualify.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT employee_id, first_name, last_name, salary FROM employees WHERE salary > (SELECT MIN(salary) FROM employees WHERE department_id = 20) ORDER BY salary DESC, employee_id;Why this works
Quantified comparisons (ANY, SOME, ALL) are an under-used SQL feature. They map directly to logical quantifiers: ∃ (ANY/SOME) and ∀ (ALL). Knowing the MIN/MAX equivalences makes them less mysterious — and lets you write portable SQL on engines (like SQLite) that lack the keywords.
Success check
An employee qualifies when their salary is greater than at least one HR salary.
Expected result
Use this output to verify values, aliases, ordering, and row count.
| employee_id | first_name | last_name | salary |
|---|---|---|---|
| 100 | John | Smith | 120000 |
| 105 | Emma | Taylor | 95000 |
| 107 | Grace | White | 90000 |
| 101 | Alice | Johnson | 85000 |
| 102 | Bob | Wilson | 80000 |
| 104 | David | Brown | 70000 |
| 109 | Ivy | Martinez | 68000 |
| 106 | Frank | Green | 65000 |
| 103 | Carol | Davis | 60000 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
CTEs & Window Functions
Practice modular CTE pipelines, deterministic window analytics, period comparisons, deduplication, frames, and gaps-and-islands.
SQL Joins
Practice reliable INNER, LEFT, FULL, CROSS, self, semi, anti, range, temporal, and many-to-many join patterns.
SQL Aggregations
Build reliable SQL metrics from aggregate functions through grain, fan-out, weighted ratios, rollups, percentiles, and approximate counts.
Open the interactive workspace and practice across SQL topics.