Re: Re: New Table Creation with PHP Variables
| From: | chris smith | Date: | Mon, 29 Dec 2008 12:43:30 +0000 |
| Subject: | Re: Re: New Table Creation with PHP Variables | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-45842@lists.php.net to get a copy of this message | ||
On Mon, Dec 29, 2008 at 10:17 AM, Keith Spiller <larentium@hosthive.com> wrote:
> Another option that would work if I can figure out the correct syntax is to
> just NULL certain values if a given condition exists. If
> product_type='course' then just use the o.product_id value for field4. If
> product_type != 'course' then use NULL for field4.
>
> CREATE TABLE $table[name]
> SELECT field1, field2, field3,
> IF(o.product_type='course', o.product_id, NULL) AS field4,
> field5, field6, field7
> FROM table1 as a, table2 as o;
>
> Is this right? Thank you for your help.
The idea is right, the format of the query isn't.
I use the case statement for this but it's up to you - work out the
right format for IF from the mysql manual.
(case when o.product_type='course' then o.product_id else null end
case) as field4
--
Postgresql & php tutorials
http://www.designmagick.com/