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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not part of aggregate function 1

Status
Not open for further replies.

simon551

IS-IT--Management
May 4, 2005
249
Hi! I'm trying to get the Key ID field of a table in a query that takes the last date listed for each Foreign Key ID. I can group by the foreign key but if I try to get the key as well then it craps out. Can you help?
Code:
SELECT MemberID, Max(ProcessDate) AS MaxDate, MembershipProcessID
FROM tblMembershipsProcessed
GROUP BY MemberID;
That MembershipProcessID field is what I'm after...

Thanks!
 

What does this give you?
Code:
GROUP BY MemberID, MembershipProcessID

Randy
 
SELECT A.MemberID, A.ProcessDate, A.MembershipProcessID
FROM tblMembershipsProcessed A INNER JOIN (
SELECT MemberID, Max(ProcessDate) AS MaxDate FROM tblMembershipsProcessed GROUP BY MemberID
) B ON A.MemberID = B.MemberID AND A.ProcessDate = B.MaxDate;

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top