views:

162

answers:

3

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

+2  A: 

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
)
Mark Byers
doing this but its not workingSELECT table.*, u.initials AS initals FROM database1.mytable AS table JOIN database.user AS u ON u.userID = table.userid WHERE id = 12548 AND recordEntryDate = ( SELECT MAX(DATE(recordEntryDate)) from {database1.myrable ) ";
+1  A: 

Or if you want todays results

SELECT * 
FROM  table 
WHERE  recordEntryDate > DATE( NOW( ) ) 
lfx
A: 

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

didnt need DATE there. Thanks!