RE: [PHP-DB] SQL conditional UPDATE
| From: | Greg Donald | Date: | Thu, 12 Oct 2000 14:18:25 +0000 |
| Subject: | RE: [PHP-DB] SQL conditional UPDATE | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3554@lists.php.net to get a copy of this message | ||
> Is there any way within one SQL query to Update to different values
> dependant on conditions. I've guessed at subqueries but cannot
> get my head
> round the syntax and web advice differs dependant on source.
> eg.
> UPDATE table SET field1 = "valuea" WHERE condition1 ELSE field1 = "valueb"
$sql = "UPDATE table SET field1 = 'valuea' ";
if($condition1){
$sql .= "where condition1 == 'some_value';
} else {
$sql .= "where condition2 == 'some_other_value';
}
--Greg