Skip to main content

Posts

Showing posts with the label and SUB QUERY?

How To Find The Highest Salary In SQL Server using MAX, DENSE_RANK, and SUB QUERY?

Method 1  SQL:- SQL Server 2nd, 3rd, 4th... Highest salary using MAX ,   DENSE_RANK, and  SUB QUERY ! We can find the 2 nd , 3 rd , 4 th   ... n th   highest salary using SQL Server the below query,  In the below query use top 1 for the 2 nd   highest salary, top 2 for the 3 rd   highest salary, top 3 for the 4 th   highest salary,.... n th   for the (n+1) highest salary. Method 2 for MySQL:- You can use LIMIT  to get 2 nd , 3 rd , 4 th   ... n th   highest salary! Examples using  MAX ,   DENSE_RANK in SQL ==================================== DECLARE @Employees TABLE (   employee_id INT,   name VARCHAR(25),   salary INT ) INSERT INTO @Employees (employee_id, name, salary) VALUES  (1, 'Anil', 62000), (2, 'Alok', 55000), (3, 'Ajay', 70000), (4, 'Rahul', 62000), (5, 'Diya', 75000); SELECT  SALARY,     DENSE_RANK() OVER (ORDER BY SALARY DESC) AS SAL...