I have 2 tables, descriptions of vehciles and a itorical table of lat/long as they move. Both tables have an Id key (PK and FK).
My SELECT looks like this
SELECT vehicles.id, vehicles.description, vehicles.type,
positions.time_stamp, positions.latitude, positions.longitude
FROM vehicles
INNER JOIN positions
ON vehicles.id=positions.id
and I would like to ORDER and LIMIT it so that it only shows the join values for latest poisiotn reported for each vehicle.
How can I do that? Thanks
[Update] I created this SqlFiddle demo, which doesn't give the desired result.
I think I need something along the lines of
ORDER BY positions.time_stamp DESC
LIMIT SELECT COUNT(*) FROM vehicles
if only that were valid syntax :-/
[Further update] for those who are concerned by the order in which thinsg execute:
- there will be no deletions from the
positions
table, only insertions - insertions will be every few minutes for each vehicle
- I can live with the odd anomlous blip, whcih I exect would be exceeding rare
- it is highly unlikely the the details of the vehicles will change, all I am doing is adding new locations
Does that make it any easier?