示例数据库查询失败;您能帮我解决问题吗?

时间:2019-02-11 05:28:55

标签: mysql database wordpress

我正在尝试更新一个名为“ dogs_postmeta”的Wordpress数据库表。 以下是我的查询,它非常适合显示所有适当的数据。

select meta_value as field_i_want_to_change, i.url as data
from dogs_postmeta
inner join (select a.post_id, CONCAT('https://mydomain/wp-content/uploads/', b.meta_value) as url
from
dogs_postmeta a, dogs_postmeta b
where
a.meta_key = '_thumbnail_id' and
b.post_id = a.meta_value and
b.meta_key = '_wp_attached_file'
) i
on i.post_id = dogs_postmeta.post_id
where
dogs_postmeta.meta_key = "_seopress_pro_rich_snippets_article_img"
limit 100;

我想更新现有字段-带上述“数据”属性的meta_value。我已经在这工作了好几个小时了。

这就是我尝试过的。

update dogs_postmeta
set dogs_postmeta.meta_value = i.url
from (select a.post_id, CONCAT('https://mydomain/wp-content/uploads/', b.meta_value) as url
from
dogs_postmeta a, dogs_postmeta b
where
a.meta_key = '_thumbnail_id' and
b.post_id = a.meta_value and
b.meta_key = '_wp_attached_file'
) i
inner join dogs_postmeta on dogs_postmeta.post_id = i.post_id 
where
dogs_postmeta.meta_key = "_seopress_pro_rich_snippets_article_img";

我收到此错误消息-

  

查询(1064)中的错误:'from附近的语法错误(选择a.post_id,   CONCAT('https://mydomain/wp-content/uploads/',b.meta_va'在第3行

...但是我确定这不是问题。

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

update dogs_postmeta as d
inner join (select a.post_id,  b.meta_value as url
from
dogs_postmeta a, dogs_postmeta b
where
a.meta_key = '_thumbnail_id' and
b.post_id = a.meta_value and
b.meta_key = '_wp_attached_file'
) as i on d.post_id = i.post_id 
set d.meta_value = CONCAT('https://mydomain/wp-content/uploads/', i.url)
where
d.meta_key = "_seopress_pro_rich_snippets_article_img";