从另一个 table 的列更新 table 的列
Update a table's column from another table's column
我有两个 table。一个是 payment1
,另一个是 payment2
。他们都有 4 个相互列。 Id, InvoiceNumber, TransactionCode
和 Date
。在 table payment1
中,某些 TransactionCode
不同或缺失。由于其中一些不同,我想根据它们不同的 Id
数字使用 payment2
中的 TransactionCode
更新它。
我知道这有点令人困惑,所以让我用一个例子来解释一下:
在tablepayment1中,Id为926,交易代码为5398。在tablepayment2中,Id为926,但交易代码为53269845。
in table payment1,Id为927,交易代码为空。在tablepayment2中,Id是926但是交易码是54895321.
我想说 Id
在哪里相同,使用另一个 table 更新 TransactionCode
。
我试过这个:
"update payment1 set payment1.TransactionCode=payment2.TransactionCode
from payment1
join payment2 on (payment1.TransactionCode=payment2.TransactionCode)"
这是错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '5 from payment join table63 on (payment1.TransactionCode=payment2.TransactionCode)' at line 1
提前致谢。
update payment1 TB1
set TB1.Transactioncode=(select B.Transactioncode from payment2 B
JOIN payment1 a
on a.Transactioncode=B.Transactioncode AND B.Transactioncode=TB1.Transactioncode)
UPDATE Payment1 P1
SET P1.TransactionCode= (SELECT P2.TansactionCode FROM Payment2 P2 WHERE P1.TransactionCode<>P2.TransactionCode AND P1.Id=P2.Id)
或
UPDATE Payment1
SET Payment1.TransactionCode= (SELECT Payment2.TansactionCode FROM Payment2 WHERE Payment1.TransactionCode<>Payment2.TransactionCode AND Payment1.Id=Payment2.Id)
其中,Payment1 和 Payment2 是 table 名称(假设)
并且, ID & TransactionCode 是 column Name (assumed)
我有两个 table。一个是 payment1
,另一个是 payment2
。他们都有 4 个相互列。 Id, InvoiceNumber, TransactionCode
和 Date
。在 table payment1
中,某些 TransactionCode
不同或缺失。由于其中一些不同,我想根据它们不同的 Id
数字使用 payment2
中的 TransactionCode
更新它。
我知道这有点令人困惑,所以让我用一个例子来解释一下:
在tablepayment1中,Id为926,交易代码为5398。在tablepayment2中,Id为926,但交易代码为53269845。
in table payment1,Id为927,交易代码为空。在tablepayment2中,Id是926但是交易码是54895321.
我想说 Id
在哪里相同,使用另一个 table 更新 TransactionCode
。
我试过这个:
"update payment1 set payment1.TransactionCode=payment2.TransactionCode
from payment1
join payment2 on (payment1.TransactionCode=payment2.TransactionCode)"
这是错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '5 from payment join table63 on (payment1.TransactionCode=payment2.TransactionCode)' at line 1
提前致谢。
update payment1 TB1
set TB1.Transactioncode=(select B.Transactioncode from payment2 B
JOIN payment1 a
on a.Transactioncode=B.Transactioncode AND B.Transactioncode=TB1.Transactioncode)
UPDATE Payment1 P1
SET P1.TransactionCode= (SELECT P2.TansactionCode FROM Payment2 P2 WHERE P1.TransactionCode<>P2.TransactionCode AND P1.Id=P2.Id)
或
UPDATE Payment1
SET Payment1.TransactionCode= (SELECT Payment2.TansactionCode FROM Payment2 WHERE Payment1.TransactionCode<>Payment2.TransactionCode AND Payment1.Id=Payment2.Id)
其中,Payment1 和 Payment2 是 table 名称(假设) 并且, ID & TransactionCode 是 column Name (assumed)