I am trying to pull off this query without running an inner query, but can’t seem to get the records correctly.
I have two tables (naming convention changed for readability) …
report
report_id
name
report_status_log
report_id
code
timestamp
A report can have several status logs. I’m trying to get all reports where the most current report_status_log is equal to a certain code.
This won’t work…
select report.id
inner join report_status_log on report.report_id = report_status_log.report_id
where report_status_log.code = 'finished'
… because although ‘finished’ might be in the status logs, it isn’t necessarily always the latest log record.
Is there a way to do this? Or should I be selecting from report_status_log table instead of the report table?
1 Answer