@koshtinimesh8247

select DISTINCT salary 
from emp
order by salary desc 
limit 2,1;

@gaziabbas3028

Select * from employee order by salary desc offset 2 rows fetch next 1 row only

@caveatashish

with cte as
(
select *, dense_rank() over (order by salary desc) as cnt
from EmployeeSalaries
)
select * from cte where cnt =3

@micro_parameshi

SELECT DISTINCT salary
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 2;

@asthitoyp

Owhh that's interesting , but here's my take :

SELECT * FROM (SELECT * FROM Employee ORDER BY salary DESC LIMIT 3) a 
ORDER BY salary ASC LIMIT 1

Thought Proccess : If we wanted to find the n number, we could just make sub query first to position the row we wanted to find, in the bottom / top position using LIMIT, and using that sub query we could find the n row in the top / bottom position using LIMIT too

So what i using here is pretty much just ORDER BY row_name ASC / DESC and LIMIT n

Let me know your though, and if it's right or wrong!

It's interesting little challenge, thanks for the learning experience!

@ProfessorCreates

Thanks for sharing 😊

@sohelalamrana

In the first example query, the second order by is not required as we are selecting only 1.

@chandrasekar1548

Select * from(select rownum r,Ename,sal from emp  order by sal desc)
Where r=3;

@vaishnav.lamaziya4898

With cte as (Select *, 
Dense_rank() over(order by salary desc) as rank_)
Select EmployeeId, salary
From cte 
Rank_ = N

@GiganFTW

How about a nice window function or a CTE?

@davestorm6718

SELECT DISTINCT sal
FROM emp
ORDER BY sal DESC
OFFSET 2 ROWS FETCH NEXT 1 ROW ONLY;

@sulagna_1262

Here's my approach:

SELECT MIN(salary) FROM (SELECT * FROM employees ORDER BY salary DESC LIMIT 3);

@rishiraj2548

Great thanks

@vinaykumarboddu854

How about use cte instead of sub query??
I mean sub query will effect the performance...

@vinitbond1402

Using dense rank is proper answer for meaning impact against interviewers...

@kuldeeppatel9898

Bro i'm data analyst but abhi tak koi job nhi lagi hai 😢

@harshsawant1106

Can we expect these type of question to be asked from freshers also ?
Like this difficulty level questions!

@gleamofcolor

The second order by is not needed as the sub query picks the top 3 records in asc order so only top 1 is sufficient