1👍
✅
Here’s how I’d solve this:
- Remove
vehicle.Locations
(otherwise you’ve got a circular relationship between the two tables) - Add a
timestamp
field tolocation
, which has the time at which the vehicle arrives at a particular location - Make sure you always insert an entry into
vehicle
before referencing it inlocation
To find a vehicle’s current location, do a GROUP BY
search on vehicle.VehId
, and pick the one which has the greatest timestamp less than the current time.
Source:stackexchange.com