Finding Nth highest salary using SQL interview question

This is one of very common question to find the Nth highest salary using sql.

Create table Command:-

 

  1. Generic Solution:- This solution use correlated subquery. Below given query can be use to find 2nd, 3rd……nth highest salary in an employee table. This solution will work on any database but it can little slower due to subquery.

     
  2. Mysql Specific Solution:- In Mysql we can use limit to solve this problem and it is fast solution but it is vendor specific.

     

    Please add comment if there is any better solution. Thanks in advance.