using UPDATE & SELECT with mysql in PHP
Posted: Thu Oct 01, 2009 1:17 pm
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..
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.
Any help would be greatly appreciated.
Thanks,
Peter
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