Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the records for the latest timestamp mysql

Tags:

php

mysql

how do I get all the records for latest date. The date filed in my db is called recordEntryDate and it is in this form 2010-01-26 13:28:35

Lang: php DB: mysql

like image 802
Asim Zaidi Avatar asked Apr 22 '10 18:04

Asim Zaidi


2 Answers

You could do this:

SELECT *
FROM table1
WHERE DATE(recordEntryDate) = (
   SELECT MAX(DATE(recordEntryDate))
   FROM table1
)

Note that this query won't be able to take advantage of an index on recordEntryDate. If you have a lot of rows this similar query might be faster for you:

SELECT *
FROM table1
WHERE recordEntryDate >= (
   SELECT DATE(MAX(recordEntryDate))
   FROM table1
)
like image 113
Mark Byers Avatar answered Sep 20 '22 03:09

Mark Byers


SELECT * 
FROM table1 
WHERE DATE(recordEntryDate) = ( 
   SELECT MAX((recordEntryDate))
   FROM table1 
) 

Didn't need DATE there.

like image 24
Asim Zaidi Avatar answered Sep 23 '22 03:09

Asim Zaidi