Posts

Showing posts from June, 2010

Find nth Highest Salary from Employee Table

How to Find 2nd ,3rd or upto....Nth highest Salary of any employee in SQl Step 1 Create Table Create Table emp ( empName nvarchar(max), Salary int ) Step 2 Insert records 1 ) Insert into values emp ('John',2000) 2 ) Insert into values emp ('Kim',5000) 3 ) Insert into values emp ('Walter',1500) 4 ) Insert into values emp ('Obama',3000) 5 ) Insert into values emp ('John Vincet',2500) 6 ) Insert into values emp ('Womek',3500) Step 3 Query Find the 2nd Highest Salary from emp Table Select * from emp a Where (2=(Select Count(Distinct b.Salary) from emp b Where b.Salary >= a.Salary)) Step 4 Execute the Step 3 Query Step 5 For find the nth Highest Salary from emp Table Select * from emp a Where (n=(Select Distinct(b.Salary) from emp b Where b.Salary >= a.Salary)) Step 6 Check the Ouptut..