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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.