删除2加入get错误 - mysql

时间:2017-05-05 08:04:15

标签: mysql

我正在尝试在MYSQL中运行此删除查询(通过phpMyAdmin)并且我一直收到此错误:

DELETE
p,pm 
from wp_posts p
inner join wp_postmeta pm on pm.post_id = p.id
where p.id in (SELECT  MIN( id ) AS min_id
      FROM wp_posts inner join wp_postmeta on (wp_posts.ID=wp_postmeta.post_id and  meta_key = 'old_id')
      WHERE post_type = 'post'
      GROUP BY meta_value
      HAVING COUNT( * ) > 1)

任何想法为什么?

1 个答案:

答案 0 :(得分:1)

查看您的代码
您不应该在IN子句

的子选择中使用
DELETE p, pm 
from wp_posts as p
inner join wp_postmeta as pm on pm.post_id = p.id
where p.id in (SELECT  MIN( id ) 
      FROM wp_posts 
      inner join wp_postmeta on (wp_posts.ID=wp_postmeta.post_id 
                                  and  meta_key = 'old_id')
      WHERE post_type = 'post'
      GROUP BY meta_value
      HAVING COUNT( * ) > 1)