我正在使用此查询从wp_postmeta表中选择某一行
SELECT *
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.meta_value
WHERE (wp.ID IS NULL) AND (pm.meta_key = '_wpcf_belongs_books_id')
它工作正常,但是当我尝试使用DELETE
时DELETE
FROM wp_postmeta pm
LEFT JOIN fddb_wp_posts wp ON wp.ID = pm.meta_value
WHERE (wp.ID IS NULL) AND (pm.meta_key = '_wpcf_belongs_books_id')
它返回错误
#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本对应的手册,以便在'pm LEFT JOIN fddb_wp_posts wp附近使用正确的语法wp.ID = pm.meta_value WHERE(wp.ID IS NULL)AND'在第2行
有关如何使其发挥作用的任何建议吗?
答案 0 :(得分:1)
如果您有一个包含多个表的delete语句,则需要为要删除的表命名。在delete
关键字
DELETE pm
FROM fddb_wp_postmeta pm ...
答案 1 :(得分:0)
DELETE
FROM fddb_wp_postmeta where
meta_value not in (select wp.ID from fddb_wp_posts wp)
and meta_key = '_wpcf_belongs_books_id'