Groups | Blog | Home
all groups > sql server new users > february 2006 >

sql server new users : calculating 2nd highest


Amit Mohod
2/3/2006 12:00:00 AM
Hi All,

Can anybody tell me what will be the SQL Query for finding the employee
with second highest salaray in the company. There may be several employees.
ur help will be of gr8 help

Regards

m.bohse NO[at]SPAM quest-consultants.com
2/3/2006 3:24:33 AM
select top 1 with TIES (salary) from employees e1
where salary < (select Max (salary) from employees)
order by salary desc

M
Lawrence Garvin
2/4/2006 11:08:39 AM
Or....

declare @employees table (
employee int identity(1,1) not null,
salary money
)

insert into @employees
select 100 union all
select 150 union all
select 200


Select Top 1 s1.employee, s1.salary from (
Select Top 2 employee, salary from @employees order by salary desc
) s1
order by s1.salary


[quoted text, click to view]

AddThis Social Bookmark Button