【发布时间】:2015-09-02 11:11:04
【问题描述】:
我有两张桌子。一个是payment1,另一个是payment2。他们都有4个相互列。 Id, InvoiceNumber, TransactionCode 和 Date。在表payment1 中,一些TransactionCode 不同或缺失。由于只是其中一些不同,我想根据它们不同的Id 编号使用payment2 中的TransactionCode 对其进行更新。
我知道这有点令人困惑,所以让我用一个例子来解释一下:
在表 payment1 中,Id 为 926,Transaction code 为 5398。在表 payment2 中,Id 为 926,但 transaction code 为 53269845。
在表 payment1 中,Id 为 927,交易代码为空。在表 payment2 中,Id 为 926,但交易代码为 54895321。
我想说Ids 哪里相同,用另一个表更新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
先谢谢了。
【问题讨论】:
-
样本数据和正确的数据库标签会有很大帮助。
-
您使用的是哪个 DBMS?后格雷斯?甲骨文?
-
我在 phpMyAdmin 上使用 MySQL
-
那么,付款 2 表的数据正确吗?
-
向我们展示您的尝试。您可能需要使用
update..join语句。去谷歌上查询。尝试一下。如果它不起作用,请在此处发布错误。
标签: mysql sql join sql-update