Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem to get record with Max (UpdatedDate)

Status
Not open for further replies.

adasoft

Programmer
Jan 31, 2002
132
IN
Hi, I have written following Query

( Select PersonnelNumber , dtEmpAccount.EmployeeID ,AccountID, AttributeCode, CurrentValue, UpdatedDate,AttributeUnit , recordType
FROM dtEmpAccount, Employee, dtAccountDef Where Employee.EmployeeID = dtEmpAccount.EmployeeID
AND dtEmpAccount.AccountID=dtAccountDef.AttributeID AND UpdatedDate >= {d '2005-01-01'} AND Recordtype in( 'TP','PS','DR')
and AccountID in (Select dtAccountDef.AttributeID from dtAccountDef Where AttributeCode in ('AC4001','AC4002' ) )
and dtEmpAccount.EmployeeID=1
)
This query return me 4 record with didderent date.
I want to get out one with Max updated date for each AccountID

Can any one help..



 
Just a shot ...
Code:
( Select  PersonnelNumber , dtEmpAccount.EmployeeID ,AccountID, AttributeCode, CurrentValue, MAX(UpdatedDate),AttributeUnit , recordType
FROM dtEmpAccount, Employee, dtAccountDef   Where Employee.EmployeeID = dtEmpAccount.EmployeeID
AND dtEmpAccount.AccountID=dtAccountDef.AttributeID AND  UpdatedDate >= {d '2005-01-01'}  AND Recordtype in( 'TP','PS','DR') 
and   AccountID in  (Select dtAccountDef.AttributeID from dtAccountDef  Where AttributeCode in ('AC4001','AC4002'  ) )  
 and  dtEmpAccount.EmployeeID=1 
group by PersonnelNumber , 
        dtEmpAccount.EmployeeID ,AccountID, AttributeCode, CurrentValue, AttributeUnit , recordType)

Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top