Update all table rows but top N in Mysql

Posted by arthurprs on Stack Overflow See other posts from Stack Overflow or by arthurprs
Published on 2011-01-09T14:37:33Z Indexed on 2011/01/09 14:53 UTC
Read the original article Hit count: 171

Filed under:
|

I was trying to run the following query

UPDATE blog_post SET `thumbnail_present`=0, `thumbnail_size`=0, `thumbnail_data`=''
WHERE `blog_post` NOT IN (
 SELECT `blog_post`
 FROM blog_post
 ORDER BY `blog_post` DESC
 LIMIT 10)

But Mysql doesn't allow 'LIMIT' in an 'IN' subquery.

I think I can make a select to count the table rows and then make an ordered update limited by 'COUNT - 10', but I was wondering if there is a better way.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql