我想跟隨更新查詢連接,但它不會更新匹配行。MySQL更新多個連接不工作
UPDATE table1 T1
INNER JOIN table2 T2 ON T2.id=10
INNER JOIN table3 T3 ON T3.category_id=T2.category_id
SET T1.value=T3.value
WHERE T1.id=T3.id
是否支持使用嵌套連接更新查詢?
我想跟隨更新查詢連接,但它不會更新匹配行。MySQL更新多個連接不工作
UPDATE table1 T1
INNER JOIN table2 T2 ON T2.id=10
INNER JOIN table3 T3 ON T3.category_id=T2.category_id
SET T1.value=T3.value
WHERE T1.id=T3.id
是否支持使用嵌套連接更新查詢?
UPDATE table1 T1
SET T1.value=T3.value
INNER JOIN table2 T2 ON T2.id=10
INNER JOIN table3 T3 ON T3.category_id=T2.category_id
WHERE T1.id=T3.id
我很想說你的查詢應該可以工作。但是,也許MySQL不喜歡你的第二行的連接條件與table1沒什麼關係?
以下工作?
UPDATE table1 T1
INNER JOIN table3 T3 ON T3.id = T1.id
INNER JOIN table2 T2 ON T2.category_id = T3.category_id
SET T1.value = T3.value
WHERE T2.id = 10
對不起@凱文,沒有看到你回答 – Strawberry
這將是更ususal地看到,查詢這樣寫......
UPDATE table1 T1
JOIN table3 T3
ON t3.id = t1.id
JOIN table2 T2
ON T2.category_id = T3.category_id
SET T1.value = T3.value
WHERE T2.id=10;
什麼錯誤? –
它不會更新匹配的行 – LoganPHP