HardCode
HardCode

Reputation: 1633

Copy Column Value from One table into Another Matching IDs

I have two tables

 t1
        id  |  value
        1   |   -
        2   |   -
 t2
       parent_id  |  p_value
        1         |   254
        2         |   124

I want to copy the column p_value from t2 into t1 where parent_id = id

Upvotes: 2

Views: 2412

Answers (3)

Nishu Tayal
Nishu Tayal

Reputation: 20840

Try this:

   Update t1, t2 set t1.value = t2.p_value where t1.id = t2.parent_id;

Upvotes: 1

Siva
Siva

Reputation: 8058

Try this

update t1 join t2 on t2.parent_id= t1.id set t1.value = t2.p_value

Upvotes: 0

alexblum
alexblum

Reputation: 2238

update t1, t2 set t1.value = t2.p_value where t1.id=t2.parent_id

Upvotes: 6

Related Questions