Answer the question
In order to leave comments, you need to log in
How to group messages by subject, sender and recipient?
Good afternoon, ladies and gentlemen! I'm breaking my head and still can't break it. And the task is not so difficult.
The message table has the following columns id, object_id, from, to. I want to display the last messages of the dialogs with one request. In turn, dialogs are grouped not only by from and to, but also by object_id. That is, if we have the same interlocutors, but different topics, then these will be different dialogues. Something similar is in gmail.
I googled examples for grouping by sender and recipient, but I can’t figure out how else to attach a topic.
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
Why didn't you try the await in else option? If you correctly understood the meaning of the question, then await should help, because it will wait for the promise to be fulfilled
As far as I understand message is exactly a table of messages and not dialogs, in the simplest case, the latest messages can be selected like this
SELECT
*
FROM
`messages`
WHERE
`id` IN (
SELECT
max(`id`)
FROM
`messages`
GROUP BY
`object_id`,
`from`,
`to`
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question