SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 highest paid employee from the table?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shammu1978
Starting Member

India
2 Posts

Posted - 04/16/2007 :  09:16:04  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 04/16/2007 :  09:24:23  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
http://www.sqlteam.com/item.asp?ItemID=566

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

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 04/16/2007 :  10:13:26  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

Sweden
30115 Posts

Posted - 04/16/2007 :  11:10:15  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
22744 Posts

Posted - 04/16/2007 :  22:58:45  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1222 Posts

Posted - 04/16/2007 :  23:04:17  Show Profile  Reply with Quote
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

India
2 Posts

Posted - 04/17/2007 :  06:10:22  Show Profile  Reply with Quote
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

Sweden
30115 Posts

Posted - 04/17/2007 :  06:24:25  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
22744 Posts

Posted - 04/17/2007 :  07:09:26  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

Sweden
30115 Posts

Posted - 04/17/2007 :  07:17:11  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Madhi, don't take it personal...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

bpgupta
Yak Posting Veteran

India
75 Posts

Posted - 04/17/2007 :  07:20:49  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 04/17/2007 :  07:24:59  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
"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"

Edited by - harsh_athalye on 04/17/2007 07:25:17
Go to Top of Page

bpgupta
Yak Posting Veteran

India
75 Posts

Posted - 04/17/2007 :  07:28:55  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 04/17/2007 :  11:27:48  Show Profile  Reply with Quote
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

India
22744 Posts

Posted - 04/17/2007 :  11:30:05  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000