Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete all rows except

When I execute this query:

DELETE FROM `wp_posts` WHERE id NOT IN 
  (SELECT id FROM wp_posts WHERE post_status = 'publish')

I get the following error message:

You can't specify target table 'wp_posts' for update in FROM clause

Not sure what the syntax issue is here.

like image 354
keruilin Avatar asked Dec 10 '22 00:12

keruilin


1 Answers

This can be done without using a sub-query. Please try the following

DELETE FROM 'wp_posts' WHERE post_status != 'publish'
like image 105
Chetter Hummin Avatar answered Jan 09 '23 06:01

Chetter Hummin