DEV Community

shubham mishra
shubham mishra

Posted on • Originally published at developerindian.com

SQL query to find second highest salary using dens_rank function ?

This is Question is most use full in Sql interview ,Below is Employee Table and we are going to write Sql Query using Dense rank function that is windowing function :

Name age salary department
shubham mishra 31 20000 computer
rahul kumar 20 30000 electric

select Name , age , salary   , 
dens_rank  over (partition by  department    order by  salary desc ) as rank 
from 
Employee 
where rank =2
Enter fullscreen mode Exit fullscreen mode

This Solution is provided by Shubham mishra This article is contributed by Developer Indian team. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. Also folllow our instagram , linkedIn , Facebook , twiter account for more

Top comments (0)