I need to do a left outer join like this:
SELECT
tblProjects.*,
tblNotes.NoteID,
tblNotes.regDate AS lastUpdatedNote
FROM
tblProjects
LEFT OUTER JOIN tblNotes ON tblProjects.ProjectID = tblNotes.ProjectID
But a project can have several notes and in this case im only interested in the one with MAX(regDate) how can i add this condition to the sql above? Or do i have to grab all the notes for each project and filter out the latest in code?
So i only want one row per project and in that row i want the lastUpdatedNote info.
Thx 🙂
In MS SQL you can do something like this:
Replace with
CROSS APPLYif you need only those projects that have notes.or with CTE:
Replace with
INNER JOINif you need only those projects that have notes.