Mysql a table grouped according to two fields to remove weight, is there a SQL boss (I have solved it myself)

demand background

A message record table that takes out the message records related to the current user, and then the previous messages of the two same users show only the latest message, and remove the message
repeatedly.

Datasheet

clipboard.png

8,, :

1,4,5

,sql,

group,idid id
8,group send_time ok

clipboard.png

Mar.28,2021

which field does your current user correspond to, and why do you take record 1, 4, 4, 5, instead of record 3, 4, 4, 5


just provides an idea. You need to consider the performance yourself

.
// 
SELECT * FROM (SELECT * FROM message ORDER BY send_time DESC ) AS tempData GROUP BY from_user_id ORDER BY id ASC
Menu