Alexd2
Alexd2

Reputation: 1114

Update table data from another table

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

Answers (4)

Romil Kumar Jain
Romil Kumar Jain

Reputation: 20775

UPDATE First,Second SET First.type=Second.type
WHERE First.id=Second.id;

Upvotes: 0

bitoshi.n
bitoshi.n

Reputation: 2318

Try

UPDATE `FIRST` AS f 
INNER JOIN `SECOND` AS s ON f.id=s.id
SET f.type=s.type

Upvotes: 0

triclosan
triclosan

Reputation: 5724

update First f, Second s 
set f.type = s.type
where f.id=s.id

Upvotes: 0

eggyal
eggyal

Reputation: 126025

Your syntax is incorrect. Try instead:

UPDATE First, Second
SET    First.type = Second.type
WHERE  First.id   = Second.id

Upvotes: 1

Related Questions