Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 707
Craig van Tonder Avatar asked Aug 04 '12 21:08

Craig van Tonder


1 Answers

SELECT id, timestamp FROM updates ORDER BY timestamp DESC LIMIT 1
like image 74
Vitor M Avatar answered Oct 19 '22 16:10

Vitor M