0

我正在尝试使用 join 来跟踪更新查询,但它不会更新匹配的行。

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 是否支持嵌套连接的更新查询?

4

3 回答 3

2
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
于 2013-10-16T13:56:02.380 回答
1

我很想说您的查询应该有效。但是,也许 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
于 2013-10-16T14:09:27.230 回答
0

看到这样写的查询会更常见......

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;
于 2013-10-16T14:23:53.100 回答