【问题标题】:Example database query failing; can you help me troubleshoot?示例数据库查询失败;你能帮我解决问题吗?
【发布时间】:2019-02-11 05:28:54
【问题描述】:

我正在尝试更新名为“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;

我想更新现有字段 - 带有上述“数据”属性的元值。我已经在这几个小时没有成功。

这是我尝试过的。

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 (select a.post_id, CONCAT('https://mydomain/wp-content/uploads/', b.meta_va' 在第 3 行

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

谁能帮我解决这个问题?

【问题讨论】:

  • CONCATSET dogs.... = CONCAT(....) 放在同一行。
  • 我之前试过。但这样做后出现新的错误消息 - 查询中的错误 (1064): 'from (select a.post_id, b.meta_value as url from dogs_postmeta a, dogs_postme' at line 3 附近的语法错误
  • 我刚刚尝试完全不使用 CONCAT,但仍然收到错误消息。
  • 同时删除子查询。

标签: mysql database wordpress


【解决方案1】:
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";

【讨论】:

  • 谢谢各位,这是我的解决方案。我一直在插话并更改了一些格式以达到上述要求。
猜你喜欢
  • 2011-01-24
  • 2020-09-03
  • 2021-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-24
相关资源
最近更新 更多