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

后端 未结 22 1345
太阳男子
太阳男子 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条回答
  •  Happy的楠姐
    2020-11-21 23:24

    Generic answer for future developers.

    SQL Server

    UPDATE 
         t1
    SET 
         t1.column = t2.column
    FROM 
         Table1 t1 
         INNER JOIN Table2 t2 
         ON t1.id = t2.id;
    

    Oracle (and SQL Server)

    UPDATE 
         t1
    SET 
         t1.colmun = t2.column 
    FROM 
         Table1 t1, 
         Table2 t2 
    WHERE 
         t1.ID = t2.ID;
    

    MySQL

    UPDATE 
         Table1 t1, 
         Table2 t2
    SET 
         t1.column = t2.column 
    WHERE
         t1.ID = t2.ID;
    

提交回复
热议问题