How to SELECT by MAX(date)? How to SELECT by MAX(date)? mysql mysql

How to SELECT by MAX(date)?


This should do it:

SELECT report_id, computer_id, date_enteredFROM reports AS aWHERE date_entered = (    SELECT MAX(date_entered)    FROM reports AS b    WHERE a.report_id = b.report_id      AND a.computer_id = b.computer_id)


Are you only wanting it to show the last date_entered, or to order by starting with the last_date entered?

SELECT report_id, computer_id, date_enteredFROM reportsGROUP BY computer_idORDER BY date_entered DESC-- LIMIT 1 -- uncomment to only show the last date.


Accordig to this: https://bugs.mysql.com/bug.php?id=54784 casting as char should do the trick:

SELECT report_id, computer_id, MAX(CAST(date_entered AS CHAR))FROM reportsGROUP BY report_id, computer_id