17. Second Highest, No LIMIT
MediumAdvanced Filteringcorrelated subqueryMAX of a filtered set
Sometimes you can't reach for LIMIT/OFFSET (some dialects
won't allow it in a subquery, and interviewers like to forbid it). A nested
MAX does the job.
Task: return a single value second_highest — the second largest distinct
salary — without using LIMIT, OFFSET, or a window function.
Tables
Loading schema…
Expected outputrow order doesn't matter
Computing expected output…
This is the result for the example data above. On Submit your query is graded against this example plus 4 hidden edge cases — 5test cases in all. A sloppy query that only fits the example won't pass.
SQL· SQLite · runs in your browser
⌘/Ctrl+↵ run · ⇧⌘/Ctrl+↵ submit
Run a query to see its output here.