[UPHPU] MySQL - Multiple-table UPDATE equivalent for MySQL 3.23

Mac Newbold mac at macnewbold.com
Tue Nov 2 15:40:40 MST 2004


Saturday at 4:47am, Jeremy Burgess said:

>This is what I want to do:
>UPDATE T1, T2
>SET T1.field1 = T2.field2
>WHERE T1.ID = T2.ID
>
>However, according to the manual ***"*Starting with MySQL 4.0.4, you can
>also
>perform |UPDATE| operations that cover multiple tables" [1]
>
>Am I reading that correctly?
>*
>*Does anyone have a solution to this seemingly elementary problem?

You're right, in older MySQL, you can't do multi-table updates.

I'm assuming this is a one-time thing, not something you're trying to put
in a script. Given that, here's a workaround:

select concat("update t1 set field1='",field2,"' where id='",id,"';")
from t2;

Then run the result of that query into mysql.

Mac

--
Mac Newbold		MNE - Mac Newbold Enterprises, LLC
mac at macnewbold.com	http://www.macnewbold.com/



More information about the UPHPU mailing list