Forum Moderators: open

Message Too Old, No Replies

Delete old entries in a MySQL database

         

thing3b

10:03 pm on Nov 26, 2006 (gmt 0)

10+ Year Member



I am having trouble writing an SQL statement and was wondering if some guru could help me.

What I am trying to do is delete all the old entries in a database table. I only want 10 entries that have the ParentID of 5.

To show the rows that I want to delete, I use the following SELECT statement:


SELECT * FROM `table` WHERE `ParentID`=5 ORDER BY `id` DESC, `date` DESC
LIMIT 11 , 99999

Can someone show me how I can change this SELECT statement to a DELETE statement, so that it deletes the rows instead?

eelixduppy

11:36 pm on Nov 26, 2006 (gmt 0)




[url=http://dev.mysql.com/doc/refman/5.0/en/delete.html]DELETE[/url] FROM `table` WHERE `ParentID`=5 LIMIT 11 , 99999

Best of luck!

FalseDawn

3:15 am on Nov 27, 2006 (gmt 0)

10+ Year Member



I hope you spotted the "deliberate" mistake of missing the ORDER BY out of the solution :-)

eelixduppy

3:37 am on Nov 27, 2006 (gmt 0)



...because of the LIMIT

oops :)