我在wordpress基础上做了自己的自定义表,现在我需要使用来自wopdpress表的数据更新表(thundbail链接)
这里选择查询
SELECT p.post_parent, guid
FROM wp_postmeta AS pm
INNER JOIN wp_posts AS p ON pm.meta_value=p.ID
WHERE pm.post_id = 1552
AND pm.meta_key = '_thumbnail_id'
ORDER BY p.post_date DESC
LIMIT 1
答案: post_parent(fullproducts = postid)| guid(fullproducts = image)
1552 | URL
我尝试使用此代码更新此表
UPDATE full_products, wp_postmeta AS pm
SET full_products.image = wp_postmeta.guid
INNER JOIN wp_posts AS p ON pm.meta_value=p.ID
WHERE pm.post_id = full_products.postid
AND pm.post_id = 1552
AND pm.meta_key = '_thumbnail_id'
ORDER BY p.post_date DESC
LIMIT 1
但是这个查询不起作用。你能检查一下吗?
答案 0 :(得分:0)
UPDATE
使用INNER JOIN
的方法有语法错误,正确的语法是
UPDATE full_products a
LEFT JOIN wp_postmeta AS pm
ON a.postid = pm.post_id
LEFT JOIN wp_posts AS p
ON pm.meta_value=p.ID
SET a.image = pm.guid
WHERE pm.post_id = 1552
AND pm.meta_key = '_thumbnail_id'