Question:
what is the mysql query to delete the last 10 or 100 entry?
dijital_self
2007-09-10 22:04:48 UTC
i don't know what function to use?

i know how to retrieve the last 10 entry by using
exp:
"SELECT * FROM table1 WHERE column = 12 ORDER BY id DESC LIMIT 0,5"

but what is the query to delete the last 5 or 10 entry?

right know i'm using foreach by passing the last 5-10 entry to an array. but what if i want to delete the last 100 entry? if i use an array i'm sure there'll be a performance problem

thx before
Four answers:
oracle128au
2007-09-10 23:14:28 UTC
DELETE FROM tbl_bookings ORDER BY booking_id DESC LIMIT 10
anonymous
2007-09-10 22:23:02 UTC
DELETE FROM table1 WHERE id in

(SELECT id FROM table 1 WHERE column = 12 ORDER BY id DESC LIMIT 0.10)
expertaziz
2007-09-10 22:57:39 UTC
Try :

DELETE *

FROM Table1

WHERE id IN (SELECT Top 10 Table1.id FROM Table1 Order by id DESC);
Albert L
2007-09-10 22:51:12 UTC
Better to select your data in your application, verify that you are deleting the correct data and delete them one by one. If you have more than one person accessing your data in your application, they could be writing to the file while you are deleting the last amount and it would make your command dangerous



You could select a range of ID's, put them into a comma separated string of ID's and execute the command "delete from table where ID in ('id1','id2',etc)" rather than executing the delete command for every item.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...