Suppose i have two tables
declare @emp table
(
EmpID int,
EmpName varchar(10)
)
declare @Remu table
(
EmpID int,
Sal Decimal(10,2),
PaidYear varchar(10)
)
I want maximum salary grouped on PaidYear (With Ties)
Expected OUTPUT
EmpID EmpName PaidYear Sal
1 Jon 2001 2000
2 Smith 2001 2000
3 Nash 2003 4000
4 Hoge 2005 5000
5 Peter 2005 5000
I have an issue when using Join
select e.EmpID,e.EmpName,r.Sal,r.PaidYear from @emp e
inner join
(select max(Sal) as Sal,PaidYear from @Remu group by PaidYear)r
on e.EmpID=???
when i select EmpID in
select max(Sal) as Sal,PaidYear from @Remu group by PaidYear
i have to Group by PaidYear and EmpID,which won't give the desired result as i expected.
How to solve this.I want a query which should be compatible with SQL Server 2000.