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
 General SQL Server Forums
 New to SQL Server Programming
 query to retrieve max bal
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

add7
Starting Member

2 Posts

Posted - 11/25/2012 :  10:35:48  Show Profile  Reply with Quote
I have to write a query that retrieves All the names of the employees who have the maximum salary in a company. say i have two tables with employee{id, name, dept} and empsalary{id, salary}. plz help

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 11/25/2012 :  10:40:00  Show Profile  Reply with Quote
Please show us what you have tried. What Salary do you consider as maximum?
Go to Top of Page

add7
Starting Member

2 Posts

Posted - 11/25/2012 :  10:49:02  Show Profile  Reply with Quote
quote:
Originally posted by sodeep

Please show us what you have tried. What Salary do you consider as maximum?



I tried by using MAX and joining the two tables. but that gives only one name and not all the names having the salary=max salary.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 11/25/2012 :  11:05:11  Show Profile  Reply with Quote
quote:
Originally posted by add7

quote:
Originally posted by sodeep

Please show us what you have tried. What Salary do you consider as maximum?



I tried by using MAX and joining the two tables. but that gives only one name and not all the names having the salary=max salary.



SELECT TOP 1 WITH TIES *
FROM Table
ORDER BY Salary DESC



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 11/25/2012 :  11:10:04  Show Profile  Reply with Quote
or

SELECT *
FROM
(
SELECT DENSE_RANK() OVER (ORDER BY Salary DESC) AS Rnk,*
FROM Table
)t
WHERE Rnk=1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.08 seconds. Powered By: Snitz Forums 2000