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( ) )
精彩评论