3

我正在尝试使用带有子查询的更新语句的内部联接...您能帮我解决语法问题吗---以及如何在 sql server 中使用 AS 子句作为别名???以下是我想要做的:

Update Table1 
inner join table2
set table1.value1 = (select table2.value1 where table1.value 1 ....)

任何的想法??

4

4 回答 4

7

如果您需要使用子查询来执行更新,您可以这样做:

UPDATE t1
SET t1.value = t2.value
FROM Table1 t1
JOIN
(
    SELECT id, value
    FROM table2
) t2
ON t1.id = t2.id
于 2012-04-17T15:00:51.080 回答
2

一种方法是给表起别名:

update t1
set    table1.value1 = t2.value1
from   table1 as t1
join   table2 as t2
on     t1.id = t2.t1_id
于 2012-04-17T14:48:47.237 回答
1

你应该试试

UPDATE table1 SET t1.value1 = t2.value2 
FROM table1 t1
INNER JOIN table2 t2 
    ON t1.field1 = t2.field2
于 2012-04-17T14:48:41.713 回答
0
UPDATE Table1 t1
    INNER JOIN (
        SELECT id, value
        FROM table2
    ) t2 USING(id)
SET t1.value = t2.value
于 2017-08-15T00:41:57.687 回答