You can specify an offset with a keyword LIMITin your query to save the very last 20 lines. However, according to the MySQL documentation, there is no easy way to limit the offset to the last; instead, they offer the following:
To get all rows from a specific offset to the end of the result set, you can use some large amount for the second parameter.
So this SQL should do the trick:
DELETE FROM table ORDER BY id DESC LIMIT 20, 18446744073709551615;
source
share