On the one hand, you use table aliases that are not defined anywhere ( T2
, T1
, etc.), and this can very well solve your problem. If not, the correct syntax is highly dependent on SQL taste.
For example, in SQL Server syntax
UPDATE T2 SET T2.dept = 'HUMAN RESOURCE' FROM Table2 T2 INNER JOIN Table1 T1 ON T1.[ID] = T2.[ID]
Even though you donβt even need a connection here, you just want to
UPDATE Table2 T2 SET T2.dept = 'HUMAN RESOURCE' WHERE EXISTS(SELECT * FROM Table1 T1 ON T1.[ID] = T2.[ID])
In MySQL syntax
UPDATE FROM TABLE2 AS T2 INNER JOIN TABLE1 as T1 ON T2.id = T1.id SET T2.Dept = 'Human Resources'
Of course, the WHERE EXISTS
approach also works for MySQL
UPDATE FROM Table2 AS T2 SET Dept="Human Resources" WHERE EXISTS (SELECT * FROM Table1 T1 ON T1.[ID] = T2.[ID]);
source share