List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:April 28 2003 1:52am
Subject:Re: IF in an UPDATE query
View as plain text  
At 0:34 +0100 4/28/03, Peter Lovatt wrote:
>Hi
>
>Is this possible in MySql 3.23.xx
>
>
>UPDATE delivery_addresses
>             IF(delivery_addressID ="99",
>             SET
>             default_value =  "1"
>             ELSE
>             SET
>             default_value =  "0")
>             WHERE
>             buyerID = "'.$GLOBALS["buyerID"].'"
>             ';
>
>The idea is to set an address as default and to set all the others as not
>the default in one query

Close, but it'd be more like this:

UPDATE delivery_addresses
SET default_value = IF(delivery_addressID="99","1","0")
WHERE ...

>
>in two queries
>
>//set all to 0
>UPDATE delivery_addresses
>SET
>default_value =  "0"
>WHERE
>buyerID = "'.$GLOBALS["buyerID"].'"
>
>//set default record with value 1
>UPDATE delivery_addresses
>SET
>default_value =  "1"
>WHERE
>buyerID = "'.$GLOBALS["buyerID"].'"
>AND delivery_addressID ="99"
>
>Anyone know the correct syntax??
>
>
>Thanks
>
>Peter


-- 
Paul DuBois
http://www.kitebird.com/
sql, query
Thread
enforce participation constraint?Stephen Fromm28 Apr
  • IF in an UPDATE queryPeter Lovatt28 Apr
    • Re: IF in an UPDATE queryPaul DuBois28 Apr
RE: IF in an UPDATE queryKen Gaul28 Apr