delete all records but the last 15 in mysql

I am trying to figure out how to write a MySQL statement that will look in my table and delete all records but the last 15 that were inserted

Any help
LVL 1
cbielichAsked:
Who is Participating?
 
Manuel Marienne-DuchêneITMCommented:
TRY THIS

DELETE FROM your_table WHERE your_id_key NOT IN (SELECT your_id_key FROM your_table ORDER BY your_id_key  DESC LIMIT 15)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.