按主键更新另一个表oracle,SQL根据ID匹配从一个表更新到另一个表

我相信一个连接的UPDATE FROM将有助于:

MS SQL

UPDATE Sales_Import SET Sales_Import.AccountNumber = RAN.AccountNumber FROM Sales_Import SI INNER JOIN RetrieveAccountNumber RAN ON SI.LeadID = RAN.LeadID;

MySQL和MariaDB

UPDATE Sales_Import SI, RetrieveAccountNumber RAN SET SI.AccountNumber = RAN.AccountNumber WHERE SI.LeadID = RAN.LeadID;

将内容从一个表格复制到另一个表格的简单方法如下:

UPDATE table2 SET table2.col1 = table1.col1, table2.col2 = table1.col2, ... FROM table1, table2 WHERE table1.memberid = table2.memberid

您也可以添加条件来获取复制的特定数据。

对于SQL Server 2008 +使用MERGE而不是专有的UPDATE ... FROM语法有一些吸引力。

除了作为标准的SQL并因此更具可移植性之外,如果源端有多个连接的行(因此在更新中使用多个可能的不同值),而不是最终的结果是不确定的。

MERGE INTO Sales_Import USING RetrieveAccountNumber ON Sales_Import.LeadID = RetrieveAccountNumber.LeadID WHEN MATCHED THEN UPDATE SET AccountNumber = RetrieveAccountNumber.AccountNumber;

不幸的是,select使用哪一个可能不会纯粹地归结为偏爱的风格。 在SQL Server中MERGE的实现已经受到各种错误的困扰。 Aaron Bertrand在这里汇编了一份报告的清单。

似乎你正在使用MSSQL,然后,如果我没有记错,它是这样做的:

UPDATE [Sales_Lead].[dbo].[Sales_Import] SET [AccountNumber] = RetrieveAccountNumber.AccountNumber FROM RetrieveAccountNumber WHERE [Sales_Lead].[dbo].[Sales_Import].LeadID = RetrieveAccountNumber.LeadID

我有同样的问题, foo.n

你可能感兴趣的:(按主键更新另一个表oracle)