Try it. It joins the statusLog statusLog
, which pulls the highest (hence the most recent, I think) statusLogId
for each ticket_ticketId
. This retrieves the statusLogId
for the ticket. A further connection then matches statusId
with statusLogId
located in the first connection.
SELECT t.*, slid.statusId FROM ticket t LEFT JOIN ( SELECT ticket_ticketId, MAX(statusLogId) AS statusLogId FROM statusLog GROUP BY ticket_ticketId ) sl ON t.ticketId = sl.ticket_ticketId JOIN statusLog slid ON slid.statusLogId = sl.statusLogId
source share