DEV Community

shubham mishra
shubham mishra

Posted on • Originally published at developerindian.com

1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay