I have the following articles mysql table:
id | date
1 | 2013-02-16 00:00:00
2 | 2013-02-17 00:00:00
I want to get a comma separated list of the ids (1,2) and the last date value (2013-02-17 00:00:00)
I use the following query:
SELECT GROUP_CONCAT(id),date FROM articles ORDER BY date DESC
The query selects the first date value it encounters (2013-02-16 00:00:00), how to make it select the last one instead?
Thanks
select group_concat(id),
max(date) as max_date
from your_table
What about use MAX
:
SELECT GROUP_CONCAT(id),MAX(date)
FROM articles
And the fiddle: http://sqlfiddle.com/#!2/4e957/3
用这个:
SELECT GROUP_CONCAT(id),date FROM articles ORDER BY date ASC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.