I am attempting to find the latest log entries in my MySQL database. I cooked up this query late last night but upon testing today it does not seem to be returning the correct data.
SELECT MAX(id), hostName, email, info, time
FROM log
WHERE time >= DATE_SUB(NOW(), INTERVAL 1 HOUR)
GROUP BY hostName
ORDER BY `time` DESC
The query runs just fine, but none of the other fields seem to match the id column. It grabs the max id number, but the hostName, email, and info do not match the id, and they are not the latest. I've spent a few hours spinning my wheels on this (I'm a MySQL noob and just doing this for fun) so I'm pretty confused now..
Thanks for any help!
EDIT: Wow thanks for all the responses! Sorry for the confusion, I should have said "I want the latest log per hostname!" <- That is specifically what I need.