Using the results of a SELECT to perform an UPDATE

I read in the mySQL manual, “Currently, you cannot update a table and select from the same table in a subquery.” So what is the best way to take the user IDs from this first query…


SELECT uID 
FROM users
WHERE sponsorID = 717 
   and memberType = 'No' 
   and uID in (select uID from campaigns where type = 'Enrollment' and answer in ('Contact', 'Purchase') 
   and status = 'Undiscovered');

…and then turn right around and update the campaigns table with this

update campaigns set status = 'Discovered' where uID in (the uIDs from the result of the first query)

Thanks!

try this –

UPDATE campaigns 
INNER
  JOIN users
    ON users.uID = campaigns.uID  
   AND users.sponsorID = 717 
   AND users.memberType = 'No' 
   AND users.status = 'Undiscovered'
SET    campaigns.status = 'Discovered' 
 WHERE campaigns.type = 'Enrollment' 
   AND campaigns.answer in ('Contact', 'Purchase')    

Thank you Rudy!