I’m trying to update a column while joining it to another table. I’ve used below query, but it gave me error.
UPDATE TABLE_2
INNER JOIN
TABLE_1
ON (T2.ID=T1.ID)
SET TABLE_2.DEPT='HUMAN RESOURCE'
WHERE TABLE_2.DEPT='HR'
AND T1.COMPANY =1
Can anyone help me on this?
Thanks.
For one thing, you’re using table aliases that aren’t defined anywhere (
T2,T1etc) and that may very well solve your problem. If not, the correct syntax very much depends on SQL flavor.For example, in SQL Server the syntax is
Although you don’t even need a join here really, you just want
In MySQL the syntax is
Of Course, the
WHERE EXISTSapproach also works for MySQL