good_evening
good_evening

Reputation: 21739

WHERE id IN doesn't work in UPDATE

UPDATE statistics'
SET money = money + '$money'
WHERE member_id IN
((SELECT member_id FROM races WHERE l_id = '$mem_id'), $other_id)

What's wrong with that? I want to retrieve all member_ids from races and also include to member_id $other_id. Without $other_id it works.

By the way, it gives me "Subquery returns more than 1 row" error.

Upvotes: 1

Views: 1097

Answers (3)

Mark Byers
Mark Byers

Reputation: 838086

Another way to do it:

(SELECT member_id FROM races WHERE l_id = '$mem_id'
UNION
SELECT $other_id)

Upvotes: 4

hsz
hsz

Reputation: 152206

Try with:

UPDATE statistics
   SET money = money + $money
 WHERE member_id IN (
       SELECT member_id
         FROM races
        WHERE l_id = $mem_id 
       )
    OR member_id = $other_id

And suggestion - for int type columns do not use apostrophs.

Upvotes: 7

x2.
x2.

Reputation: 9668

subquery returns member_id and $other_id

Upvotes: 4

Related Questions