Tested in Build PGSQL (14300) or MSSQL (14306)
Change Request:
SELECT ad.ORG_NAME AS "Account", chdt.CHANGEID AS "Change ID", chdt.CREATEDTIME AS "Created Time", ownaaa.FIRST_NAME AS "Change Owner", priodef1.PRIORITYNAME AS "Priority", chdt.TITLE AS "Title", orgaaa.FIRST_NAME AS "Change Requester",sdpnotes.description "Last notes added", LONGTODATE(sdpnotes.recordeddate) "Last notes added date",notedaddedby.first_name "Last notes added by" FROM ChangeDetails chdt
LEFT JOIN SDUser orgsd ON chdt.INITIATORID=orgsd.USERID
LEFT JOIN AaaUser orgaaa ON orgsd.USERID=orgaaa.USER_ID
LEFT JOIN SDUser ownsd ON chdt.TECHNICIANID=ownsd.USERID
LEFT JOIN AaaUser ownaaa ON ownsd.USERID=ownaaa.USER_ID
LEFT JOIN PriorityDefinition priodef1 ON chdt.PRIORITYID=priodef1.PRIORITYID
LEFT JOIN changetonotes ctn on ctn.changeid=chdt.changeid
LEFT JOIN sdpnotes on sdpnotes.notesid=ctn.notesid
INNER JOIN AccountSiteMapping asm ON chdt.SITEID=asm.SITEID
INNER JOIN AccountDefinition ad ON asm.ACCOUNTID=ad.ORG_ID
LEFT JOIN aaauser notedaddedby on notedaddedby.user_id=sdpnotes.userid
where sdpnotes.notesid = (select max(changetonotes.notesid) from changetonotes where changetonotes.changeid=ctn.changeid) or ctn.changeid is NULL