question

John 1 1 avatar image
John 1 1 asked

Update a table from another table

Hi

I have 2 tables and want to update my second table with one column of the first one :

Table A : name                    
Table B : name_f                    

i tried this unsuccessfully :

update B set name_f = p1.name                    
from                    
A p1, (select * from B )  p2                    
where                    
p1.id = p2.id                    

what's wrong ? i use mysql Thanks Jonathan

updatemysql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Madhivanan avatar image
Madhivanan answered

Use one of the following

1 update p2 set name_f = p1.name from A p1, (select * from B ) p2 where p1.id = p2.id             
            
2 update p2 set name_f = p1.name from A as p1 inner join B as p2 on p1.id = p2.id            
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.