SQL update from one Table to another based on a ID match

后端 未结 22 1597
太阳男子
太阳男子 2020-11-21 22:49

I have a database with account numbers and card numbers. I match these to a file to update any card numbers to the account number, so

22条回答
  •  日久生厌
    2020-11-21 23:33

    I believe an UPDATE FROM with a JOIN will help:

    MS SQL

    UPDATE
        Sales_Import
    SET
        Sales_Import.AccountNumber = RAN.AccountNumber
    FROM
        Sales_Import SI
    INNER JOIN
        RetrieveAccountNumber RAN
    ON 
        SI.LeadID = RAN.LeadID;
    

    MySQL and MariaDB

    UPDATE
        Sales_Import SI,
        RetrieveAccountNumber RAN
    SET
        SI.AccountNumber = RAN.AccountNumber
    WHERE
        SI.LeadID = RAN.LeadID;
    

提交回复
热议问题