tags:

views:

95

answers:

3

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.

+4  A: 

subquery returns member_id and $other_id

x2
And how can I make it work with only one query?
hey
hsz already answered
x2
+6  A: 

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.

hsz
Superb! Works perfect. Thank you very much. :)
hey
"for int type columns do not use apostrophs."I have protected it with addslashes() function, so I think it is okay, isn't?
hey
For strings - ok, but I preffer `mysql_escape_string()`.If you work with ints, floats, etc - cast them `$id = (int) $_GET['id'];` (or `(float)`, etc) and it will be enough.
hsz
Yes, great idea. ;)
hey
+4  A: 

Another way to do it:

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