I have 2 tables:
Table workflow
Request_Id, Step ID
123, 4
123, 7
198, 5
Table Steps
Step_Id, Step_num
4, 30
7, 12
5, 172
I am trying to return all records in table Workflow, where Steps.step_num is the max for that record.
My result should look like this:
Request_Id, Step_Id, Step_Num
123, 4, 30
198, 5, 172
I’ve tried this, but I don’t get the right Step_ID:
select request_id, step_id,max(step_num) from
(
select ww.request_id as request_id, ww.step_id as step_id, st.step_num as step_num
from workflow ww
left join steps st on ww.step_id=st.step_id) as s
group by request_id
Please help, I am stuck 🙂
1 Answer