Jump to content

DELETE ALL entries, but not the last 10 recent entries.


jasonc

Recommended Posts

i wish to delete all but the 10 most recent entries that fit a certain criteria.

 

i have tried this but does not work, how would i correctly remove all but the most recent ones?

 

DELETE FROM 
    `table` 
  WHERE 
    `user` = 'username' 
  ORDER BY 
  `date` DESC
  LIMIT 10, 1000000

You have an error in your delete query. Please RTM and don't apply things blindly - http://dev.mysql.com/doc/refman/5.0/en/delete.html

 

Thank you Ken, I have tried the query drectly in mysql query window and it gives me the following eror but I do not know how to fix this so it removes all but the most recent 10 entries.

 

i was able to select them ok but not delete them.

using the follwing query.

SELECT * 
FROM

(
  SELECT * 
  FROM 
    `table` 
  WHERE 
    `user` = 'username' 
  ORDER BY 
  `date` DESC
  LIMIT 5, 1000000
) as DT
ORDER BY 
  `date`

 

I did take a look at the link you gave and this is a page I have previously looked at but I can not see how to delete al but the most recent entries method.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.