我正在尝试使用带有子查询的更新语句的内部联接...您能帮我解决语法问题吗---以及如何在 sql server 中使用 AS 子句作为别名???以下是我想要做的:
Update Table1
inner join table2
set table1.value1 = (select table2.value1 where table1.value 1 ....)
任何的想法??
我正在尝试使用带有子查询的更新语句的内部联接...您能帮我解决语法问题吗---以及如何在 sql server 中使用 AS 子句作为别名???以下是我想要做的:
Update Table1
inner join table2
set table1.value1 = (select table2.value1 where table1.value 1 ....)
任何的想法??
如果您需要使用子查询来执行更新,您可以这样做:
UPDATE t1
SET t1.value = t2.value
FROM Table1 t1
JOIN
(
SELECT id, value
FROM table2
) t2
ON t1.id = t2.id
一种方法是给表起别名:
update t1
set table1.value1 = t2.value1
from table1 as t1
join table2 as t2
on t1.id = t2.t1_id
你应该试试
UPDATE table1 SET t1.value1 = t2.value2
FROM table1 t1
INNER JOIN table2 t2
ON t1.field1 = t2.field2
UPDATE Table1 t1
INNER JOIN (
SELECT id, value
FROM table2
) t2 USING(id)
SET t1.value = t2.value