Assuming I have a table foo
where I have something like this:
id
, user_id
, timestamp
, some_value
What I want to do is remove all rows that aren't the newest N per user.
The deletion itself could be handled by a:
DELETE FROM foo WHERE id NOT IN (...)
so you could rephrase the problem into: How do I get the newest N(there might be less) rows for each user. This means if I have U users I may end up with N*U rows so LIMIT
wont really work.