July 21, 2008 at 5:52 am
Hi Friends,
Given an employee table( with columns Emp_ID,Emp_Name,Emp_Salary), how would you find out the fifth highest salary?
Please tell
July 21, 2008 at 6:09 am
July 21, 2008 at 6:30 am
Like this:
Select Top 1 * From (
Select Top 5
Emp_ID,Emp_Name,Emp_Salary
From Employee
Order By Emp_Salary
) Order By Emp_Salary DESC
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
July 21, 2008 at 10:37 am
It depends.
What if there are ties? Do you want the fifth record, even if there are five ties for highest?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
July 21, 2008 at 11:52 am
GSquared (7/21/2008)
It depends.What if there are ties? Do you want the fifth record, even if there are five ties for highest?
I think the OP wants to know the fifth highest salary, NOT the record with the 5th highest salary.
July 21, 2008 at 12:01 pm
Kaushal (7/21/2008)
GSquared (7/21/2008)
It depends.What if there are ties? Do you want the fifth record, even if there are five ties for highest?
I think the OP wants to know the fifth highest salary, NOT the record with the 5th highest salary.
Yes, but since the solution depends on how to treat ties, till he replies, I can't expand on that.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
July 21, 2008 at 12:14 pm
Hard to tell from the question alone. Michael Earl is right, we need to know more from the OP before we can really answer the question.
😎
July 21, 2008 at 12:34 pm
I am forced to agree with me as well.
July 21, 2008 at 6:18 pm
Heh... look how many people are doing homework with no try from the op... 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
July 21, 2008 at 10:30 pm
Actually, most of us have just asked for more from OP.
😎
July 22, 2008 at 6:15 am
Dang... you're right Lynn... I was blazing through a bunch of these and didn't read all the posts. My appologies. Thanks for the feedback.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 22, 2008 at 6:33 am
I'm glad I'm not the only one that does that
July 22, 2008 at 11:28 am
Michael Earl (7/22/2008)
I'm glad I'm not the only one that does that
The only one that does what? 🙂 🙂
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
July 22, 2008 at 1:05 pm
He was talking about me blazing through posts and missing stuff...:)
--Jeff Moden
Change is inevitable... Change for the better is not.
July 22, 2008 at 2:55 pm
Jeff Moden (7/22/2008)
He was talking about me blazing through posts and missing stuff...:)
ORLY? (That was the whole point of my post.)
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 15 posts - 1 through 15 (of 41 total)
You must be logged in to reply to this topic. Login to reply