开发者

get the records for the latest timestamp mysql

开发者 https://www.devze.com 2022-12-28 08:31 出处:网络
how do I get all the records for 开发者_JS百科latest date. The date filed in my db is called recordEntryDate and it is in this form 2010-01-26 13:28:35

how do I get all the records for 开发者_JS百科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


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
)


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

Didn't need DATE there.


Or if you want todays results

SELECT * 
FROM  table 
WHERE  recordEntryDate > DATE( NOW( ) ) 
0

精彩评论

暂无评论...
验证码 换一张
取 消