June 29, 2009 at 11:48 pm
Hi i want to select 3 highest Salary in a company.
Suggest me a sql query..
my table is
Emp_ID Emp_name Salary
1 Ram 12000
2 Sham 16000
3 Sharma 25000
4 Daniel 10000
5 Sonia 24000
6 Rohit 17000
June 30, 2009 at 12:05 am
Hi,
try this
select top 3 emp_id,Emp_name, salary from MyTable
order by salary desc
ARUN SAS
June 30, 2009 at 4:36 am
select top 3 sal from order by sal
June 30, 2009 at 5:10 am
Finding Nth Position without TOP :
;WITH Salary
AS (SELECT Emp_ID,Emp_Name,Salary,DENSE_RANK() OVER(ORDER BY Salary DESC ) 'Rank' FROM MyTable)
-- Finding Max 3 Salaries
SELECT * FROM Salary WHERE Rank <=3
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply