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.
Author |
Topic |
add7
Starting Member
2 Posts |
Posted - 2012-11-25 : 10:35:48
|
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
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2012-11-25 : 10:40:00
|
Please show us what you have tried. What Salary do you consider as maximum? |
|
|
add7
Starting Member
2 Posts |
Posted - 2012-11-25 : 10:49:02
|
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. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-11-25 : 11:05:11
|
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 TableORDER BY Salary DESC ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-11-25 : 11:10:04
|
orSELECT *FROM(SELECT DENSE_RANK() OVER (ORDER BY Salary DESC) AS Rnk,*FROM Table)tWHERE Rnk=1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|