MySQL update table based on another tables value

前端 未结 7 1276
心在旅途
心在旅途 2020-11-22 15:20

I have a two tables,

Here is my first table,

ID      SUBST_ID        CREATED_ID
1       031938          TEST123
2       930111          COOL123
3             


        
相关标签:
7条回答
  • 2020-11-22 16:16

    Using INNER JOIN:

    UPDATE TABLE1
    INNER JOIN TABLE2 ON TABLE1.SUBST_ID = TABLE2.SERIAL_ID
    SET TABLE2.BRANCH_ID = TABLE1.CREATED_ID;
    

    Another alternative solution like below: Here I am using WHERE clause instead of JOIN

    UPDATE 
        TABLE1,
        TABLE2
    WHERE
        TABLE1.SUBST_ID = TABLE2.SERIAL_ID
    SET 
        TABLE2.BRANCH_ID = TABLE1.CREATED_ID;
    
    0 讨论(0)
提交回复
热议问题