You need to do two queries: read max calender
for any given employee group
, then to select the rows with the same those values is calender and group.
Select vm."Employee Number" as eGroup, max(vm.Calender) as Calender From view1 vm
That part is obvious. The problem is how to inject it as a criterion for
Select vd."Employee Number", vd.Calender, vd.Performance From view1 vd where ... ?
Since aggregate functions (like max
) gives a singular result, you can use JOIN without risk of having Cartesian sets production (when all combinations of rows from two select
s are tried, NxM)
Select vd."Employee Number", vd.Calender, vd.Performance From view1 vd
Join (Select "Employee Number" as eGroup, max(vm.Calender) as maxCal From view1) as vm
On (vd."Employee Number" = vm.eGroup) and (vd.Calender = vm.maxCal)
Note, this still can produce several rows with the same Employee Number
and Calender
if that was how they were in the table. Unless you have a UNIQUE INDEX upon both those columns.