question

unforunatedba avatar image
unforunatedba asked

how to update a column from another column ?

I have an employee table with 150 employee records. now i need to change the last name of 10 employees from another table. **Employee table name :** dbo,employee (ID,firstname,lastname,dob,position,joined date,birthdate) Second table dba.updatetable (Last name ) Now how can i update the first 10 names from employee table like the same in update table. thank u
sqlqueryupdatecolumnobjects
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
ThomasRushton avatar image
ThomasRushton answered
You're looking for an `UPDATE...FROM...` statement. See the examples in the section "Updating Data Based on Data From Other Tables" in the [MSDN documentation for the UPDATE statement][1] A quick example, though: UPDATE Employee SET lastname = NewLastName FROM Employee e INNER JOIN NewLastName n ON e.ID = n.ID However, given your tables indicated above, you might want to work out *how* you're going to match the right values to be updated, as you don't seem to have anything to match on (such as the ID field in both tables)... Without that information, and/or some actual sample data, we won't be able to help much further. [1]: https://msdn.microsoft.com/en-us/library/ms177523.aspx#Examples
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.