2013-05-26 49 views
0

我沒有在WordPress的基礎自定義的表,現在我需要更新使用數據從wopdpress的表(thundbail鏈接)MySQL的更新數據,3臺

這裏選擇查詢表

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


我tryed此代碼更新此表

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

在'UPDATE'語句'INNER JOIN'是放錯了地方;把它放在'SET'關鍵字之前,與其他表一起。 – eggyal

回答

0

INNER JOIN使用UPDATE的方式有語法錯誤,正確的語法是

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' 
+0

請看正確的選擇查詢,我的更新查詢可能是錯誤的。圖像的記錄是在wp_posts,在這裏你不使用這個 – user2421781

+0

@ user2421781對不起,我剛更新它 – Fabio

+0

謝謝! 隨着你幫我得到了正確的查詢 UPDATE full_products fp LEFT JOIN wp_postmeta AS pm ON fp.postid = pm.post_id LEFT JOIN wp_posts AS p ON pm.meta_value=p.ID SET fp.image = p.guid WHERE pm.post_id = 1552 AND pm.meta_key = '_thumbnail_id' user2421781