我必须像这样摆 table 。现在 tbl2.transaction_id
来自 tbl1.id
。我想用 transaction_id
现在指向它们的 tbl1.id_trans
值更新 tbl2.transaction_id
。我可以只用一个查询来做到这一点吗?谢谢。
tbl1
+------+----------------+
| id | id_trans |
+------+----------------+
| 53 | 531 |
| 54 | 532 |
| 55 | 533 |
| 56 | 554 |
| 57 | 555 |
+------+----------------+
tbl2
+------+----------------+
| id | transaction_id |
+------+----------------+
| 10 | 53 |
| 11 | 55 |
| 12 | 56 |
+------+----------------+
最佳答案
尝试加入更新:
UPDATE tbl2 t
INNER JOIN tbl1 s
ON(t.transaction_id = s.id)
set t.transaction_id = s.id_trans
关于mysql - 从 mysql 中的另一个表更新表值,其中更新的字段是外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37672165/