K
K
Kirill Rezanov2020-09-15 09:18:15
SQL
Kirill Rezanov, 2020-09-15 09:18:15

How to correctly display dialogs with the latest messages?

Hello everyone, I've been scratching my head for a long time how to implement. There are tickets, a kind of dialogue between the site admin and users, on the tickets page I need to display information about each dialogue that the user has and his last message, but only the first messages are displayed, what could be wrong? Broke my whole head.

SELECT tickets.*, ticketID.*, users.name 
        FROM 
        users, tickets, ticketID 
        WHERE
        ticketID.ticketID = tickets.ticketID AND users.id = tickets.fromuser GROUP BY ticketID.ticketID ORDER BY tickets.id DESC


If the messages are not grouped by dialogs, then they will drop out all at once, and sorting for dialogs in this case does not work in such a way as to display the last message of the dialog, but simply displays the dialogs in the opposite direction

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2020-09-15
@ThunderCat

firstly, show the tables,
secondly, write the joins normally, then there will be no extra rows and without group buys
, thirdly, sorting should be done by date, not by id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question