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
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e49830-44d1a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e49830-44d1a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?