using UPDATE & SELECT with mysql in PHP

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
petroz
Forum Newbie
Posts: 16
Joined: Sun Sep 06, 2009 11:56 pm

using UPDATE & SELECT with mysql in PHP

Post 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
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: using UPDATE & SELECT with mysql in PHP

Post 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
Post Reply