1

当我执行以下查询时:

DELETE FROM wp_postmeta 
    WHERE post_id 
        NOT IN (
            SELECT post_id 
            FROM wp_postmeta a 
            INNER JOIN wp_sl_posts b 
            ON a.post_id = b.id
            )

我收到一条错误消息:

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

我有点知道为什么,但我真的不知道执行操作所需的语法。我已经根据这里和其他地方的答案尝试了一些不同的选择,但不是运气。

4

2 回答 2

2

尝试

DELETE wp_postmeta 
FROM wp_postmeta 
left outer JOIN wp_sl_posts b ON a.post_id = b.id
WHERE b.post_id is null
于 2012-04-28T20:17:17.940 回答
1

这基本相同,应该可以工作:

DELETE FROM wp_postmeta
WHERE post_id NOT IN (SELECT id FROM wp_sl_posts)
于 2012-04-28T20:36:20.980 回答