SELECT ti.FIRST_NAME AS "Support Rep",
wo.WORKORDERID AS "Request ID",
longtodate(wo.CREATEDTIME) AS "Created Time",
wo.TITLE AS "Subject",
aau.FIRST_NAME AS "Contact",
pd.PRIORITYNAME AS "Priority",
std.STATUSNAME AS "Request Status",
longtodate(wos.LAST_TECH_UPDATE) AS "Last Update Time",
(note.NOTESTEXT) "Notes",
longtodate(note.notesdate) "Note Added date" FROM WorkOrder wo LEFT JOIN SDUser sdu ON wo.REQUESTERID = sdu.USERID LEFT JOIN AaaUser aau ON sdu.USERID = aau.USER_ID LEFT JOIN WorkOrderStates wos ON wo.WORKORDERID = wos.WORKORDERID LEFT JOIN SDUser td ON wos.OWNERID = td.USERID LEFT JOIN AaaUser ti ON td.USERID = ti.USER_ID LEFT JOIN PriorityDefinition pd ON wos.PRIORITYID = pd.PRIORITYID LEFT JOIN StatusDefinition std ON wos.STATUSID = std.STATUSID LEFT JOIN WorkOrder_Fields wof ON wo.WORKORDERID = wof.WORKORDERID
LEFT JOIN (
select ns.WORKORDERID,ns.NOTESTEXT,ns.notesdate from Notes ns WHERE ns.NOTESID = (SELECT MAX(nts.NOTESID) FROM Notes nts WHERE nts.WORKORDERID=ns.WORKORDERID))note ON wo.WORKORDERID=note.WORKORDERID