简体   繁体   English

Python-通过从B表中选择ID来更新一个表中多个记录的最快方法

[英]Python - Fastest way to update multiple records in one table by selecting id from B table

I have two tables in MySQL, which named A and B. 我在MySQL中有两个表,分别命名为A和B。

  • A table scheme : a_id, u_id 表方案:a_id,u_id
  • B table schema : b_id, u_id B表架构:b_id,u_id

I want to update B table u_id by selecting A table's u_id, with the condition a_id is equal to b_id. 我想通过选择条件为a_id等于b_id的A表的u_id来更新B表u_id。

For example, record in A looks like ('001', 'a00'),('003', 'a01'); 例如,A中的记录看起来像('001','a00'),('003','a01'); record in B looks like ('001', ''), ('002', ''), ('003', '') B中的记录看起来像('001',''),('002',''),('003','')

I want to update B table records with the result ('001', 'a00'), ('003', 'a01') 我想用结果('001','a00'),('003','a01')更新B表记录

What is the fastest way to update the B table's u_id value? 更新B表的u_id值的最快方法是什么? Thanks you. 谢谢。

Your query should look like this: 您的查询应如下所示:

UPDATE tableB SET column2 = tableA.column2 WHERE tableB.column1 = tableA.column1

you can read up more on up update sql here . 您可以在此处阅读有关更新SQL的更多信息

Please let me know if you have any questions! 请让我知道,如果你有任何问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM