So I have two tables for dealing with messages threads and messages.
messages:
id | thread | user_from | user_to | text | created
threads:
id | user_from | user_to | created | status
I want to build a query that would fetch me threads with:
- the latest message for that thread
- the id for that thread
Until now, I have been dealing with this problem by first fetching the all threads (with proper limits of course) and then getting the latest message for each thread individually.
Any thoughts?
Update:
Table Relation: messages.thread = threads.id
Off the top of my head:
[edit] Tested and it seems to work fine.