The usual method
| The code is as follows |
Copy Code |
| SELECT * FROM table group BY column_name ORDER by id DESC |
is not able to get the maximum value of the ID within each packet.
Workaround:
Someone writes the following statement:
| The code is as follows |
Copy Code |
SELECT *,max (Dateline) as Max_line from posts GROUP by Tid order by Dateline DESC LIMIT 10
|
This statement is correct to select the maximum release time, but you can compare Dateline and max_dateline is not equal! (There may be quite
Situation, that is, the target record of the group is only one time! )
The correct approach is:
| The code is as follows |
Copy Code |
SELECT *,max (Dateline) as Max_line from posts GROUP by Tid has Dateline=max (Dateline) Order BY Dateline DESC LIMIT 10 Or SELECT * FROM (SELECT * to table ORDER BY id desc) T GROUP BY column_name ORDER by id DESC |
This will
The maximum ID value is obtained for each packet, and the last order by id DESC is then sorted by the values of the resulting IDs