Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Second highest Salary

Author  Topic 

ruchita
Starting Member

5 Posts

Posted - 2007-07-18 : 00:53:42
suppose i want to find top three salaried people i can find top 3 salary using max salary


but i have a problem i want to find Second Highest Salary suppose top 3 salaries are 10$ , 5$ and 2$ i want to find only 5$
]
can anyone help me with aquery for this

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-18 : 00:57:19
just search for it in this forum


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-18 : 01:15:24
quote:
Originally posted by khtan

just search for it in this forum


KH
[spoiler]Time is always against us[/spoiler]





you can start with the sticky in "New to SQL Server" section.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

ruchita
Starting Member

5 Posts

Posted - 2007-07-18 : 01:18:35
thanks for the replies

my syntax

select empid,max(salary)
from employees
where salary>any(select max(salary)
from employees
where rownum<=2)
is this right ?..experst plz let me know
Regds
Ruchita
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-18 : 01:49:11
quote:
Originally posted by ruchita

thanks for the replies

my syntax

select empid,max(salary)
from employees
where salary>any(select max(salary)
from employees
where rownum<=2)
is this right ?..experst plz let me know
Regds
Ruchita



Have you tried to run it ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ruchita
Starting Member

5 Posts

Posted - 2007-07-18 : 02:20:44
doesn't give the right answer ....
select max(sal) from employees
where sal> any (select max(sal) from employees
where Rownum()<=2 orderby sal desc )

can u plz help me out wats wrong ? is the syntax wrong ?
am new to sql server tried searching as per ur suggesttion but cudnt find the reqd topic
regards

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-18 : 02:34:20

Select min(sal) as sal from
(
select top 2 sal from table order by sal DESC
) T

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-18 : 05:21:00
SELECT MAX(Sal) FROM Table WHERE Sal < (SELECT MAX(Sal) FROM Table)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-18 : 07:25:06
quote:
Originally posted by Peso

SELECT MAX(Sal) FROM Table WHERE Sal < (SELECT MAX(Sal) FROM Table)


Peter Larsson
Helsingborg, Sweden


I prefer the solution I have given that can work work any N value

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-07-18 : 11:12:52
Standard job interview question #1.

Don't interviewers ever come up with anything original?



CODO ERGO SUM
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-19 : 04:19:51
quote:
Originally posted by Michael Valentine Jones

Standard job interview question #1.

Don't interviewers ever come up with anything original?



CODO ERGO SUM


I dont know why they always target second highest paid employee

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -