Reputation: 1114
I have these two tables with the same structure but with different number of datas.
Table First id INT type INT
Table Second id INT type INT
I need to update the type of the table "FIRST" with the value Type of table "SECOND" and I try to execute this statment
update First set
type = (
select Second.type
from First,
Second
where First.id=Second.id
)
But it doesn't run. Where I've mistaken?
Thanks for any suggestions.
Upvotes: 0
Views: 194
Reputation: 20775
UPDATE First,Second SET First.type=Second.type
WHERE First.id=Second.id;
Upvotes: 0
Reputation: 2318
Try
UPDATE `FIRST` AS f
INNER JOIN `SECOND` AS s ON f.id=s.id
SET f.type=s.type
Upvotes: 0
Reputation: 126025
Your syntax is incorrect. Try instead:
UPDATE First, Second
SET First.type = Second.type
WHERE First.id = Second.id
Upvotes: 1