MySQL select MAX(datetime) not returning max value

Try like this:

SELECT d.id, d.computer, d.app, d.version, d.build, a.installed
FROM data d
INNER JOIN (
  SELECT computer, app, max(DATE) AS installed
  FROM data
  GROUP BY computer, app
  ) a ON a.computer = d.computer AND a.app = d.app
WHERE placement = 'xxx'

The inner query is getting you the max(date) for each pair of computer and app, then you just join with that to get the rest of the information.


Try by casting the Datetime field

 SELECT 
            id,
            computer, 
            app, 
            version, 
            build, 
            MAX(cast(date as Datetime)) AS installed
        FROM 
            data 
        WHERE 
            placement = 'xxx'
        GROUP BY 
           app, computer, id, version, build
        ;

Tags:

Mysql

Sql

Max