Suppose I have a table employee with id, user_name, salary. How can I select the record with the 2nd highest salary in Oracle?
I googled it, find this solution, is t
WITH records AS ( SELECT id, user_name, salary, DENSE_RANK() OVER (PARTITION BY id ORDER BY salary DESC) rn FROM tableName ) SELECT id, user_name, salary FROM records WHERE rn = 2