This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input data and expected output for updating the table using SELECT JOIN statement.
Create sample tables with data:
1 2 3 4 5 6 7 8 9 |
CREATE TABLE tbl_abc (ID INT, Name VARCHAR(10)) CREATE TABLE tbl_xyz (ID INT, Name VARCHAR(10)) GO INSERT INTO tbl_abc VALUES (1,'a'),(2,'b'),(3,'c') INSERT INTO tbl_xyz VALUES (1,'x'),(2,'y'),(3,'z') GO |
UPDATE Statement:
1 2 3 4 5 6 |
UPDATE tbl_abc SET tbl_abc.Name = tbl_xyz.Name FROM tbl_abc INNER JOIN tbl_xyz ON tbl_abc.ID = tbl_xyz.ID GO |
Result:
1 2 3 4 5 6 7 8 |
SELECT *FROM tbl_abc GO ID Name ----------- ---------- 1 x 2 y 3 z |
Please try the different solution for this puzzle and share it via comment...