I have the following 3 tables. The 1st table has about 100 rows. How can I update the CompanyId in the first table with its corresponding value from the 3rd table via one update statement?
T1
-----------------------------
FileId | CompanyId
-----------------------------
ABC | NULL
DEF | NULL
T2
-----------------------------
FileId | UserId
-----------------------------
ABC | 123
DEF | 456
T3
-----------------------------
UserId | CompanyId
-----------------------------
123 | V1
456 | V2
Use this statement:
UPDATE T1
SET COMPAYID = T3.CompanyId
FROM T1 INNER JOIN T2 ON T1.FILEID = T2.FILEID
INNER JOIN T3 ON T2.USERID = T3.USERID
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments