Forum Moderators: open

Message Too Old, No Replies

Mysql update problem

cant get it wo work

         

dramstore

4:09 pm on Nov 24, 2005 (gmt 0)

10+ Year Member




I'm using mysql v3.23.58 and doing my first attempt at updating a row from another table (using PHPmyadmin).

simple example:
table a - fields f1 and f2
table b - fields f1 and f2

I know other forms of sql quite well so have tried:

update a
from b
set a.f2 = b.f2
where a.f1 = b.f1

also tried:

update a, b
set a.f2=b.f2
where a.f1=b.f1

and seemingly endless other possible combinations, can't get anything to work.

I have looked for mysql examples on the web and am beginning to think its possibly because of the older version of mysql I'm using?

Any one any ideas?

Appologies if this has been posted already, the webmasterworld google search has gone now, since the banning of robots.

Thanks.

coopster

4:25 pm on Nov 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Your suspicions are correct. You can perform UPDATE operations covering multiple tables starting with MySQL 4.0.4.

[dev.mysql.com...]

dramstore

4:27 pm on Nov 24, 2005 (gmt 0)

10+ Year Member



Thanks for that.

Is there any work around you know of/can think of for this version?

coopster

4:42 pm on Nov 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



SELECT from secondary table first, then UPDATE primary with value(s) from the result set.

dramstore

4:56 pm on Nov 24, 2005 (gmt 0)

10+ Year Member



Thanks - I'll give that a try.