The two tables are salary\_employee and employee

**employee\_salary**

```
salary_id  emp_id  salary

```

**Employee**

```
emp_id |    first_name | last_name |    gender  | email | mobile  | dept_id  | is_active

```

Query to get the all employees who have nth highest salary where n =1,2,3,... any integer 

```
SELECT  a.salary, b.first_name 
FROM    employee_salary a 
JOIN    employee b 
ON      a.emp_id = b.emp_id 
WHERE   a.salary = (
                      SELECT    salary 
                      FROM      employee_salary  
                      GROUP BY  salary 
                      DESC     
                      LIMIT 1 OFFSET N-1
                   )

```

**My Questions:** 

1) Is there any better and optimized way we can query this, 

---

2) Is using LIMIT an good option

---

3) We have more options to calculate the nth highest salary, which is the best and what to follow and when? 

One option using : 

```
SELECT *
   FROM employee_salary t1
   WHERE ( N ) = ( SELECT COUNT( t2.salary )
                   FROM employee_salary t2 
                   WHERE  t2.salary >=  t1.salary 
                 )

```

**Using Rank Method**

```
SELECT salary
FROM
(
  SELECT @rn := @rn + 1 rn,
       a.salary
  FROM tableName a, (SELECT @rn := 0) b
  GROUP BY salary DESC
) sub
WHERE sub.rn = N

```