This is the table structure:
CREATE TABLE `reports` (
`report_id` int(11) NOT NULL auto_increment,
`computer_id` int(11) NOT NULL default \'0\',
`date_e
I use this solution having max(date_entered)
and it works very well
SELECT
report_id,
computer_id,
date_entered
FROM reports
GROUP BY computer_id having max(date_entered)
SELECT report_id, computer_id, date_entered
FROM reports
WHERE date_entered = (
SELECT date_entered
FROM reports
ORDER date_entered
DESC LIMIT 1
)
select report_id, computer_id, date_entered
into #latest_date
from reports a
where exists(select 'x' from reports
where a.report_id = report_id
group by report_id having max(date_entered) = a.date_entered)
select * from #latest_leave where computer_id = ##
It works great for me
SELECT report_id,computer_id,MAX(date_entered) FROM reports GROUP BY 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_entered
FROM reports
GROUP BY computer_id
ORDER 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 reports
GROUP BY report_id, computer_id