Page 1 of 1

using UPDATE & SELECT with mysql in PHP

Posted: Thu Oct 01, 2009 1:17 pm
by petroz
Hi Guys,

I am trying to update multiple columns with selections from another table. From what I have read, I should be able todo something like this..

Code: Select all

UPDATE table1 SET col1 = (SELECT col1 FROM table2 WHERE col1 = 'value'), col2 = (SELECT col2 FROM table2 WHERE col2 = 'value');


Here is an example below... But I cant seem to get it to work once I choose the second SET of columns to be updated.

Code: Select all

$update = "UPDATE requests2 SET `resp_name` = (SELECT `name` FROM `users` WHERE `uid` = 'abc123'), `resp_organization` = (SELECT `organization` FROM `users` WHERE `uid` = 'abc123a') WHERE `resp_uid` = 'abc123'";



Any help would be greatly appreciated.

Thanks,
Peter

Re: using UPDATE & SELECT with mysql in PHP

Posted: Fri Oct 02, 2009 2:47 pm
by akuji36
Hello

take a look at the following link:

http://www.mark-holt.co.uk/2008/11/18/h ... her-table/

thanks

Rod
webpagesofease.com