Reputation: 12712
I have the following scenario in mySql, is it possible to update the values with an update statement?
I'd like to set the value table 1.A to the value of 2.B when 1.A matches 2.C
Table1
columnA
Table2
columnB
columnC
I'm thinking of running the following - will it work?
Update Table1 SET Table1.columnA=Table2.columnB
WHERE Table1.columnA = Table2.columnC
Any help much appreciated,
Upvotes: 0
Views: 147
Reputation: 67085
How about something like this:
UPDATE Table1
JOIN Table2
ON Table1.columnA = Table2.columnC
SET Table1.columnA=Table2.columnB
Upvotes: 1
Reputation: 121932
You can use this query -
Update
Table1, Table2
SET
Table1.columnA = Table2.columnB
WHERE
Table1.columnA = Table2.columnC;
...or this query with JOIN clause -
Update Table1 JOIN Table2
ON Table1.columnA = Table2.columnC
SET
Table1.columnA = Table2.columnB
Upvotes: 1