MySQL - Select most recent date out of a set of several possible timestamps?

走远了吗. 提交于 2020-01-01 04:16:19

问题


I would like to know if this is possible using a mysql query:

I have a table called updates.

In the updates table I have 2 columns, id and timestamp.

I have 5 rows each with the same id but with different date timestamps. An example of this timestamp would be the value: 2012-08-04 23:14:09.

I would like to select only the most recent timestamp value out of the 5 results. This could also be explained by saying that I would like to select the value that is closest to the current date and time. How could I do this?


回答1:


SELECT id, timestamp FROM updates ORDER BY timestamp DESC LIMIT 1



回答2:


have you tried SELECT MAX(timestamp) ?



来源:https://stackoverflow.com/questions/11812215/mysql-select-most-recent-date-out-of-a-set-of-several-possible-timestamps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!