MySQL Forums
Forum List  »  General

HELP - how to retrieve multiple fields on max 1 field
Posted by: Bad Programmer
Date: May 14, 2018 11:38AM

I've got a table that has IDs and a Date field.
I need to retrieve only the last record for each PersonID, DepartmentID combination.


I need the Department & StatusName in the recordset which requires joins.
If I use MAX(StatusID) I get the right StatusID (I think by luck) but still the wrong StatusName.
How can I get the records I need?

SELECT
StatusRecordID, PersonID, DepartmentID, StatusID, MAX(DateCreated), Department, StatusName
FROM status_records
INNER JOIN departments on status_records.DepartmentID = departments.DepartmentID
INNER JOIN status_mstr on status_records.StatusID = status_mstr.StatusID

Options: ReplyQuote


Subject
Written By
Posted
HELP - how to retrieve multiple fields on max 1 field
May 14, 2018 11:38AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.