Copy all values from one column in one table to column in other table that share same username

Viewed 32

I need to copy all values from column in one table into column in another table and make sure that username matches the values in the column. In both tables there is a column with username. I have tried:

insert into [Table1] (columnName)
select columnName
from [Table2]
where [Table1].username = [Table2].username]

However condition clause like that doesn't work. In what way should I write condition [Table1].username = [Table2].username], to make sure to update values in right rows (where username is the same?)

1 Answers

You have write UPDATE query instead of INSERT

UPDATE T1
SET T1.columnName = T2.columnName
FROM [Table1] T1
JOIN [Table2] T2 ON T1.username = T2.username
Related