2016-10-10 110 views
0

我想更新MS SQL中的訂單表,它有兩個具有相同訂單ID但不同版本號的行 我想更新s_address1字段版本1行與發行版2中的數據由ORDER_ID加盟,我嘗試以下SQL,但我得到一個模棱兩可的表錯誤消息更新列從一行到另一行

update orders 
SET im1.s_address1=im2.s_address1 
FROM orders im1 
INNER JOIN orders im2 
ON im1.order_id=im2.order_id 
WHERE im1.owner_id ='SHX' AND im2.owner_id='SHX' 

請幫 感謝

+5

,而不是'更新orders'使用'更新im1'別名 – techspider

+0

可能的重複[使用SQL Server中的JOIN更新表](http://stackoverflow.com/questions/1604091/update-a-table-using-join-in-sql-server) – techspider

回答

0
update im1 
SET im1.s_address1=im2.s_address1 
FROM orders im1 
INNER JOIN orders im2 
ON im1.order_id=im2.order_id 
WHERE im1.owner_id ='SHX' AND im2.owner_id='SHX'