You can try something like this:
DELETE from chat WHERE id < (SELECT max(ID)-50 FROM chat)
This will work if your values โโfor the identifier increase with step 1. Or you can use something like:
DELETE FROM chat WHERE id NOT IN (SELECT id FROM ( SELECT ID FROM chat ORDER BY datetime_col DESC LIMIT 50) t )
Mithrandir
source share