I have a query that pulls a list of records from a report and has a few other information tables join.
The table is a log of changes to the database and can contain several like, but not exactly alike records. We decided instead of displaying the long list of changes, we would only show the most recent change. I tried to use the group by function to show only the latest change per group, but i discovered that I can order or sort it to show only the most recent record. It seems to pick the first record in the list. The s reference table that stores names of other users who are not staff and who are being changed by the staff.
Here is my query
select *, old.methodName as oldName, new.methodName as newName, s.firstName as fName, s.lastName as lName from changeReport
left join methodLookup as old on (old.methodID = changeReport.oldMethod)
left join methodLookup as new on (new.methodID = changeReport.newMethod)
join students on (s.ID = changeReport.ID)
left join staffaccounts on (changeReport.staffID = staffaccounts.staffID)
where newSubMethod = '$bnu' and date(timestamp) = CURRENT_DATE OR oldSubMethod = '$bnu' and date(timestamp) = CURRENT_DATE
group by s.ID
order by changeReport.rID desc
How do I modify this query (Maybe a sub query? I cant seem to get it to work) to show the data is already shows, but the most recent record in the group? Everything is time stamped properly.