I have two tables that look like this:
Table: cases
id
name
status
case_no
Table: notes
id
case_id
note_date
notes
I'd like to be able to create a query that grabs the data from the cases table and only the most recent entry from the notes table for each row in the cases table. So far I'm having no luck at all.
Any pointers would be greatly appreciated
I have been having same problem recently and this forum has helped me a lot but I found the OMG Ponies answer isn't complete. It works for those cases with notes but it doesn't for cases without notes which is my issue. My answer is similar but instead joining the group query with notes, I join it with cases.
It would be:
It's also valid to get just cases with notes removing one left keyword or both
This will return only the cases with notes attached:
If you want all cases, regardless if they have a note attached:
Also it is a common practice to keep the pointer to the last note id directly in
cases
table and support it with trigger