Update field value of one table equal to field value of another table

When performing database operations, sometimes we need to synchronize a field in the two associated tables, that is, assign the value of field A in table 1 to field B in table 2, and table 1 and table 2 are associated through field C. The SQL statement is as follows (Sql server and MySql are written slightly differently):

SQL Sever:

写法1: update t2 set t2.B=t1.Afrom Table2 t2 ,Table t1 where t2.C2=t1.C1 
写法2: UPDATE Table2 SET B= (SELECT A FROM Table1 WHERE C1=Table2.C2)

MySQL:

update Table2 inner join Table1 on Table2.C2=Table1.C1 set Table2.B=Table1.A

 

mysql has been verified

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326070311&siteId=291194637