I have a simple web application that allows users to message each other, the user can view their inbox to see their messages. The inbox should be grouped by sender, sorted by date of the latest message from that sender and also by the inbox read status.
I thought my query was working fine however i have just noticed that the ordering of some messages are not correct! I am pretty sure its due to the group by returning any message… is there anyway around this?
Have a look at this fiddle:
http://sqlfiddle.com/#!2/565c6/1
The last message of the sorted inbox, actually has the latest message yet its at the bottom of the inbox view!
I think you’re looking for a group-wise max:
Sql Fiddle
Or, without the correlated sub-query:
Sql Fiddle