Can someone help me with a MySql query to delete all rows greater than n entries ordered by date?
I.e. say I have 1200 rows of data with a timestamp column. I need to order it by date and preserve rows only up to the first 200.
If I have only 199 rows of data, then I need to preserve them all.
Best Answer
This will keep the first 200 rows (and possibly a few more, with identical timestamps):
Additional question: Keep the first 200 rows for every user (by the
uid
column):A
(uid, timestampColumn)
will be useful with a big table.