I have a little problem here that I'll try to explain. I want to fetch the latest (highest id) maximum 10 rows (can exist more/less than 10) per each unique id in a table.
So if I'm interested in knowing the latest 10 rows from id "1" and "2" I would set the LIMIT
to 20 (2 * 10).
This is what my current query looks like right now (which incorrectly will fetch latest 20 rows of the first id since it exists more than 10 rows for that id).
SELECT positions.id
, trackedpersons.name
, trackedpersons.id
, events.name
, events.route
, positions.latitude
, positions.longitude
, positions.datetime
FROM trackedpersons
, positions
, events
WHERE trackedpersons.id IN (1,2)
AND events.id = 1
AND events.id = positions.eventid
AND positions.trackedpersonid = trackedpersons.id
ORDER
BY trackedpersons.id
, positions.id DESC
LIMIT 20;