I have a mysql query. I need to get last value from columns Lat,Lng from my table but serial_number column needs to be distinct.
How to make such a query?
This is needed as I am using this coordinates to load it to Google map. So when the Google maps loads I need to have a marker on each last coordinates where vehicle is.
Create an index on
(serial_number, time, id)for this to work fast.If you want to retrieve the last record for a certain serial_number, just use this: