I need this view to have the most recent workorder.id for each equipment_id. Right now the view looks like:
CREATE VIEW [dbo].[v_workorder_last_done] AS
select workorder.equipment_id, max(workorder.id) as workorder
from workorder
where workorder.lab_complete = 'T'
group by workorder.equipment_id
Primary key is workorder.id, so it's always unique. Workorder can have multiple equipment_id records. Sometimes, max(workorder.id) is not the most recent workorder.id. I need both the equipment_id and the id for the max(workorder.create_date) for each equipment_id.
Any ideas on how to do this?