Re: SQL conditional UPDATE
| From: | php3 at developersdesk dot com | Date: | Thu, 12 Oct 2000 16:03:01 +0000 |
| Subject: | Re: SQL conditional UPDATE | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-3559@lists.php.net to get a copy of this message | ||
Addressed to: "Derek Paterson" <d.paterson@craneware.com>
php-db@lists.php.net
** Reply to note from "Derek Paterson" <d.paterson@craneware.com> Thu, 12 Oct 2000
14:46:51 +0100
>
> 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"
>
UPDATE table SET field1 = IF( condition1, 'valuea', 'valueb' );
An hour or two spend perusing the MySQL documentation might be very
valuable. Chapter 7, the MySQL Language Reference is the area to spend
most of your time.
http://www.mysql.com/documentation/mysql/commented/manual.php?section=Reference
Within that section you will find 7.4 Functions for Use in SELECT and WHERE
Clauses very useful:
http://www.mysql.com/documentation/mysql/commented/manual.php?section=Functions
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com