[英]How do I update columns in a table by joining it with 5 other tables?
I want to update a table which has only two fields test_set_id and plan_id which i can get easily from this query我想更新一个只有两个字段 test_set_id 和 plan_id 的表,我可以从这个查询中轻松获得
SELECT tp.plan_id
, r.release_id
FROM test_plan tp
, releases r
, test_run tr
, iteration i
WHERE tr.iteration_id = i.iteration_id
AND i.release_id = r.release_id
AND tr.plan_id = tp.plan_id
AND i.release_id = 1
GROUP BY plan_id
but when I run the following query, it is giving me an sql error.但是当我运行以下查询时,它给了我一个 sql 错误。
UPDATE test_set_relation
SET test_set_id
, plan_id=
( SELECT tp.plan_id
, r.release_id
FROM test_plan tp
, releases r
, test_run tr
, iteration i
WHERE tr.iteration_id = i.iteration_id
AND i.release_id = r.release_id
AND tr.plan_id = tp.plan_id
AND i.release_id = 1
GROUP BY plan_id
)
How do I fix this issue?我该如何解决这个问题?
You cannot assign multiple field values like that in SET.您不能像在 SET 中那样分配多个字段值。
SET test_set_id,plan_id=(SELECT tp.plan_id,r.release_id
This will throw the error Incorrect syntax near ','.
这将
Incorrect syntax near ','.
抛出错误Incorrect syntax near ','.
(this error message is from SQL Server) because the query is expected to have an assignment operator = next to the column name. (此错误消息来自 SQL Server)因为该查询应该在列名旁边有一个赋值运算符= 。
Your query should be formulated something along this line.您的查询应该沿着这条线制定一些东西。 Without knowing how your tables are structured, it is not possible to formulate a valid UPDATE statement.
如果不知道表的结构,就不可能制定有效的UPDATE语句。
Usage : SQL Server
syntax用法:
SQL Server
语法
UPDATE t1
SET t1.col2 = t2.col2
, t1.col3 = t2.col3
FROM table1 t1
INNER JOIN table2 t2
ON t1.col1 = t2.col1
Usage : MySQL
syntax用法:
MySQL
语法
UPDATE table t1
JOIN
SET t1.col2 = t2.col2
, t1.col3 = t2.col3
INNER JOIN table2 t2
ON t1.col1 = t2.col1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.