Hi all
I have the following table (please bear in mind that dates are in dd/mm/yyyy format):
AssetID UserName LendDate
1 AA 01/12/2012
1 BB 15/12/2012
1 CC 18/01/2013
2 DD 01/07/2011
2 CC 01/08/2011
2 AA 09/09/2011
What I would like to do is end up with:
AssetID UserName LendDate
1 CC 18/01/2013
2 AA 09/09/2011
What I am trying to show is, who is the current user for each asset - this equates to the user for each asset with the most recent date
Each query I have tried to run returns a record for each user and each asset - I only want to know the user with the most recent record for each asset
My most recent query:
SELECT ASSETLENDING.ASSETID, DIRPARTYTABLE.NAME AS UserName, MAX(ASSETLENDING.LENDINGDATE) AS LendDate FROM ASSETLENDING INNER JOIN EMPLTABLE ON ASSETLENDING.DATAAREAID = EMPLTABLE.DATAAREAID AND ASSETLENDING.EMPLID = EMPLTABLE.EMPLID INNER JOIN DIRPARTYTABLE ON EMPLTABLE.DATAAREAID = DIRPARTYTABLE.DATAAREAID AND EMPLTABLE.PARTYID = DIRPARTYTABLE.PARTYID GROUP BY ASSETLENDING.ASSETID, DIRPARTYTABLE.NAME order by assetlending.assetid
Can anybody help me out please??
Cheers
Naz