separate query
first query id
select CAST(group_concat(ids) AS CHAR(10000) CHARACTER SET utf8) as iid
from (select SUBSTRING_INDEX(group_concat(id ORDER BY 字段),',',4) as ids from `table` group by 字段) as val
query data by id
SELECT * FROM table where id in ($id)
This is also possible
select field,substring_index(group_concat( concat(field,':',field) order by field desc separator '|'),'|',5) from table group by field;
Depending on the situation
DELETE FROM xxx WHERE id NOT IN(SELECT id FROM (SELECT MAX(b.id) AS id FROM xxx b GROUP BY b.xxxx) b)
{{o.name}}
{{m.name}}