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 2005 Forums
 Transact-SQL (2005)
 highest paid employee from the table?

Author  Topic 

shammu1978
Starting Member

2 Posts

Posted - 2007-04-16 : 09:16:04
Hi

I have table named employee and trying to write an sql query to pull the third highest salary from the employee table with his name,employeenumber,department?

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-16 : 09:24:23
[url]http://www.sqlteam.com/item.asp?ItemID=566[/url]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-16 : 10:13:26
Do google search on Find Nth maximum salary

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-16 : 11:10:15
C'mon guys. He is using SQL Server 2005.
At least show him methods utilizing ROW_NUMBER() function...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-16 : 22:58:45
quote:
Originally posted by Peso

C'mon guys. He is using SQL Server 2005.
At least show him methods utilizing ROW_NUMBER() function...


Peter Larsson
Helsingborg, Sweden

Not everyone is using

Madhivanan

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

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-04-16 : 23:04:17
This article is really good. It should point you in the right direction.

http://www.sqljunkies.com/HowTo/4E65FA2D-F1FE-4C29-BF4F-543AB384AFBB.scuk
Go to Top of Page

shammu1978
Starting Member

2 Posts

Posted - 2007-04-17 : 06:10:22
Thanks for all of your comments, but nobody has given a correct reply.

"Failing" to "plan" is "Planning" to "fail" this what all are we doing right now.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-17 : 06:24:25
What have you tried so far?
Post what you have tried and we can help you.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-17 : 07:09:26
quote:
Originally posted by shammu1978

Thanks for all of your comments, but nobody has given a correct reply.

"Failing" to "plan" is "Planning" to "fail" this what all are we doing right now.


Select columns from table
where sal=(Find 3rd Maximum query)

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-17 : 07:17:11
Madhi, don't take it personal...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

bpgupta
Yak Posting Veteran

75 Posts

Posted - 2007-04-17 : 07:20:49
try this query

Select top 1 columnname from mytable
where sal =(Select sal from mytable order by Desc)

Hope it will work fine
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-17 : 07:24:59
"C'mon guys. He is using SQL Server 2005.
At least show him methods utilizing ROW_NUMBER() function...
"

I posted link only to let him/her know that there is pretty nice search functionality on this site and he can use it for his benefit.

As far as forum is concerned, I don't think he is using SQL 2005..It's my feeling that posters are just not paying much attention to the forum names anymore.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

bpgupta
Yak Posting Veteran

75 Posts

Posted - 2007-04-17 : 07:28:55
ignore the first statement , u can try this one
SELECT TOP 1 Emp_ID, Salary
FROM (SELECT TOP 2 Emp_ID, Salary FROM Emp_Det ORDER BY Salary DESC) a
ORDER BY Salary ASC
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-04-17 : 11:27:48
when you write "Thanks for all of your comments, but nobody has given a correct reply"
what we see is "I just want the answer to my homework, I don't want to learn SQL"

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-04-17 : 11:30:05
quote:
Originally posted by Peso

Madhi, don't take it personal...


Peter Larsson
Helsingborg, Sweden


No

Madhivanan

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

- Advertisement -