MySQL Forums
Forum List  »  Newbie

Re: UPDATE a field SEVERAL times in 1 UPDATE
Posted by: Rick James
Date: August 19, 2010 08:02PM

Well, this might be the least number of statements:
CREATE TEMPORARY TABLE f381454 (id INT);
INSERT INTO f381454 (id) VALUES ('1'),('2'),('4'),('3'),('4'),('4');
CREATE TEMPORARY TABLE g381454
    SELECT id, COUNT(*) as ct 
        FROM f381454 GROUP BY id;
UPDATE casinogamers c, g381454 b 
    SET c.bucks = c.bucks + b.ct
    WHERE c.id = b.id; 

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.