出發點是文章 ID,假設為 123
我現在要透過 123 去找 wp_postmeta 資料表,找到符合的 post_id = 123 時,再從該筆符合 meta_key = _thumbnail_id and 取得 meta_value = 456
然後再用 456 這個 ID 去找 wp_posts 資料表的 ID,再將該筆 guid 值拿回去給文章 ID 123 去 UPDATE 剛帶回來的 guid

資料表 wp_postmeta

post_id / meta_key / meta_value
123 / _thumbnail_id / 456

資料表 wp_posts (我要的值)

ID / guid
456 / 我要的guid值

資料表 wp_posts (帶回去取代文章)

ID / guid
123 / 將「我要的guid值」丟到這

有點弔詭,繞成這樣
但我還真的不知道怎麼表對表更新
我要更新的是同一個資料表、同一個欄位,但是不同 ID
邏輯整個死了......

我大概寫成這樣

UPDATE wp_posts
SET posts.guid = posts.guid 
FROM wp_posts posts
INNER JOIN wp_postmeta meta
ON meta.meta_key = '_thumbnail_id'
WHERE meta.post_id = posts.ID

就覺得哪裡怪怪的
我要取的資料是 wp_posts guid
但我回來要改的也是 wp_posts guid

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM wp_posts posts
INNER JOIN wp_postmeta meta 
ON meta.meta_key = '_thumbnai' at line 3
from wp_posts AS A
left join wp_postmeta AS C on C.post_id=A.ID
left join wp_posts AS B on B.ID=C.meta_value
where 1=1
and C.post_id='123'
and C.meta_key='_thumbnail_id'