Reputation: 23
I'm trying to do a fairly simple update of one column from one table to the same column in another.
I have two tables:
container (id, barcode_1, location)
test(id, barcode_1, location)
Both tables are exactly the same except for the barcode_1 column. I want to update container.barcode_1 with the values from test.barcode_1 on all matching ids.
This is the code I'm using:
update container
set container.barcode_1 = test.barcode_1
FROM container INNER JOIN test ON container.id = test.id;
When I run that code, I get this error:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM container INNER JOIN test ON container.id = test.id' at line 3
Any ideas one why this might be failing?
Upvotes: 0
Views: 32
Reputation: 77926
Your UPDATE
syntax is wrong here. It should be
update container
INNER JOIN test ON container.id = test.id
set container.barcode_1 = test.barcode_1;
(OR) Using table alias
update container c
INNER JOIN test t ON c.id = t.id
set c.barcode_1 = t.barcode_1;
Upvotes: 1