mysql group query the latest records

One line of sql

SELECT * FROM(SELECT * FROM student ORDER BY create_time DESC LIMIT 10000) s GROUP BY name

Analysis: divided into sub-query and main query, two statements

(1) The sorting is done first. When grouping, it will default to the first one of each group. The limit must be added . If not, the order will not take effect.

SELECT * FROM student ORDER BY create_time DESC LIMIT 10000

(2) Then group the first one

SELECT * FROM  s GROUP BY name

 

Guess you like

Origin blog.csdn.net/Mint6/article/details/112164427