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
 General SQL Server Forums
 New to SQL Server Programming
 NOt server programmin but please help me

Author  Topic 

keshavagrawal89
Starting Member

1 Post

Posted - 2009-07-08 : 06:55:55
i have a table named emp wid colmns : eid, ename, designation, salary. Now i want all the information abt the employee getting maximum salary in their respective designations...I used d followin querry :
Select * from emp where salary in (select max(sal) from emp group by designation);

But this doesnt work for similar values in salary column...

can anyone plaese help me out of this....

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-08 : 07:14:25
Can you give example data and wanted output please?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

rohitkumar
Constraint Violating Yak Guru

472 Posts

Posted - 2009-07-08 : 09:32:57
use ROW_NUMBER()
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-08 : 09:35:49
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/multipurpose-row-number-function.aspx
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/find-nth-maximum-value.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-08 : 10:57:28
quote:
Originally posted by keshavagrawal89

i have a table named emp wid colmns : eid, ename, designation, salary. Now i want all the information abt the employee getting maximum salary in their respective designations...I used d followin querry :
Select * from emp where salary in (select max(sal) from emp group by designation);

But this doesnt work for similar values in salary column...

can anyone plaese help me out of this....



SELECT e1.*
FROM emp e1
JOIN (SELECT designation,MAX(sal) FROM greatest
FROM emp
GROUP BY designation) e2
ON e2.designation=e1.designation
AND e2.greatest=e1.sal
Go to Top of Page
   

- Advertisement -