Search code examples
phpsqldelete-row

How to delete rows 1-12 in a MySQL table


How would I go about doing this? I already have an id field with auto increment and primary key. But yeah I need a script that does this. Everywhere I looked it just shows me how to delete single rows but never multiple rows in order.


Solution

  • You will want to LIMIT your delete to 12 rows, you will want to set it so that it deletes WHERE the id is >= to the id that it is due to start at.

    If I want to delete 12 rows, starting at (and including) id 4, from table foo:

    DELETE FROM `foo` WHERE `id` >= 4 ORDER BY `id` ASC LIMIT 12