Tech
Cheat Sheet: SQL Query Interview Questions
1. Find the Second Highest Salary
SELECT MAX ( e1 . salary )
FROM employee e1
WHERE e1 . salary < (
SELECT MAX ( e2 . salary )
FROM employee e2
);
2. Find the Nth Highest Salary
Option 1: Using LIMIT and OFFSET
SELECT DISTINCT e . salary
FROM employee e
ORDER BY e . salary DESC
LIMIT 1 OFFSET n - 1 ; -- Replace 'n-1' with the calculated offset number
Opti...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to