RE: [PHP-DB] UPDATE table1 FROM table2
Yes, it is possible: UPDATE TABLE2 SET (Field1, Field2, Field3) SELECT UpdaterField1, UpdaterField2, UpdaterField3 FROM TABLE1 WHERE SomeField LIKE 'Something' WHERE SomeField LIKE 'Something' That should work. Manual tells you more in Update section. Niklas -Original Message- From: m0sh3 [mailto:[EMAIL PROTECTED]] Sent: 2. marraskuuta 2001 13:15 To: [EMAIL PROTECTED] Subject: [PHP-DB] UPDATE table1 FROM table2 In MySQL 3.23, how to update one table using information from another table. update table1 set value1=t2.value2 from table1 as t inner join table2 as t1 using(pk_key) ??? or update table1 as t1 inner join table2 as t2 using(pk_key) set t1.value1=t2.value2 ??? Is it possible at all? Thank you -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] UPDATE table1 FROM table2
Uups! Sorry, That won't work. Do it like this: REPLACE INTO test2 (test2.ID, test2.Value) SELECT test1.ID, test1.Value FROM test1 WHERE test1.ID LIKE '1' From manual: ...REPLACE works exactly like INSERT, except that if an old record in the table has the same value as a new record on a unique index, the old record is deleted before the new record is inserted Niklas -Original Message- From: m0sh3 [mailto:[EMAIL PROTECTED]] Sent: 2. marraskuuta 2001 13:37 To: Niklas Lampén Subject: Re: [PHP-DB] UPDATE table1 FROM table2 thanx for reply but in manual there's nothing said about this form of UPDATE, just plain one. your way: how do i link fields between updated table and source table? thanx - Original Message - From: Niklas Lampén [EMAIL PROTECTED] To: 'm0sh3' [EMAIL PROTECTED] Sent: Friday, November 02, 2001 3:27 AM Subject: RE: [PHP-DB] UPDATE table1 FROM table2 Yes, it is possible: UPDATE TABLE2 SET (Field1, Field2, Field3) SELECT UpdaterField1, UpdaterField2, UpdaterField3 FROM TABLE1 WHERE SomeField LIKE 'Something' WHERE SomeField LIKE 'Something' That should work. Manual tells you more in Update section. Niklas -Original Message- From: m0sh3 [mailto:[EMAIL PROTECTED]] Sent: 2. marraskuuta 2001 13:15 To: [EMAIL PROTECTED] Subject: [PHP-DB] UPDATE table1 FROM table2 In MySQL 3.23, how to update one table using information from another table. update table1 set value1=t2.value2 from table1 as t inner join table2 as t1 using(pk_key) ??? or update table1 as t1 inner join table2 as t2 using(pk_key) set t1.value1=t2.value2 ??? Is it possible at all? Thank you -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] UPDATE table1 FROM table2
This is actually one of the more common MySQL problems which doesn't have an easy answer. The best I can offer is a bit of a kludge... but it does work. The trick is to use the Replace...Select command. The problem with this is that you can not select from the table you are replacing. But if you make a temporary copy of the tabe you are updating, then what you are wanting to do can be done with $query = create temporary table temp select * from table1; replace table1 select temp.id,table2.value2,temp.colname from table2 left join temp using(id); You just have to make sure all of the columns in table1 you don't want changed appear as temp.colname. The temp table will only exist as long as the thread does, since it was created with the temporary keyword. Sheridan Saint-Michel Website Administrator FoxJet, an ITW Company www.foxjet.com - Original Message - From: m0sh3 [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, November 02, 2001 5:14 AM Subject: [PHP-DB] UPDATE table1 FROM table2 In MySQL 3.23, how to update one table using information from another table. update table1 set value1=t2.value2 from table1 as t inner join table2 as t1 using(pk_key) ??? or update table1 as t1 inner join table2 as t2 using(pk_key) set t1.value1=t2.value2 ??? Is it possible at all? Thank you -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]