Copy data from one column to other column (which is in a different table)

后端 未结 8 1538
小鲜肉
小鲜肉 2020-11-30 20:59

I want to copy data from one column to another column of other table. How can I do that?

I tried the following:

Update tblindiantime Set CountryName          


        
8条回答
  •  半阙折子戏
    2020-11-30 21:28

    A similar question's answer worked more correctly for me than this question's selected answer (by Mark Byers). Using Mark's answer, my updated column got the same value in all the rows (perhaps the value from the first row that matched the join). Using ParveenaArora's answer from the other thread updated the column with the correct values.

    Transforming Parveena's solution to use this question' table and column names, the query would be as follows (where I assume the tables are related through tblindiantime.contact_id):

    UPDATE tblindiantime
    SET CountryName = contacts.BusinessCountry
    FROM contacts
    WHERE tblindiantime.contact_id = contacts.id;
    

提交回复
热议问题