x

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

more ▼

asked Dec 07, 2009 at 08:25 PM in Default

avatar image

John 1 1
1 1 1 1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Dec 08, 2009 at 04:23 AM

avatar image

Madhivanan
1.1k 2 5 9

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x171
x110

asked: Dec 07, 2009 at 08:25 PM

Seen: 1175 times

Last Updated: Jan 19, 2010 at 12:11 PM

Copyright 2016 Redgate Software. Privacy Policy