• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 531
  • Last Modified:

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
1 Solution
Manuel Marienne-DuchĂȘneITMCommented:

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)

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now