K
K
kirillantv2017-10-05 11:53:54
JavaScript
kirillantv, 2017-10-05 11:53:54

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

3 answer(s)
P
Pavel Didenko, 2019-06-27
@Dasslier

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

A
Alexander N++, 2017-10-05
@kirillantv

https://www.9lessons.info/2013/05/message-conversa...

M
Maxim Fedorov, 2017-10-05
@qonand

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 question

Ask a Question

731 491 924 answers to any question