Re: Use of 'as' name in where sub-clause
| From: | Ignatius Reilly | Date: | Wed, 01 Dec 2004 10:27:37 +0000 |
| Subject: | Re: Use of 'as' name in where sub-clause | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-37483@lists.php.net to get a copy of this message | ||
Very simply, because a clause
WHERE sales * cost > 100
would look up to "sales" and "cost" in the expression as SELECT fields.
Your clause will wotk if you add "sales" and "cost" to the SELECT fields,
but that would not be economical:
- you don't need them in the result
- you will execute the caclulation twice
In any case it good personal hygiene to use aliases
Ignatius
_________________________
----- Original Message -----
From: "Ross Honniball" <ross@bookshop.jcu.edu.au>
To: "php DB" <php-db@lists.php.net>
Sent: 01 December 2004 10:53
Subject: [PHP-DB] Use of 'as' name in where sub-clause
> Hi All,
>
> In MySql, you CAN'T do the following:
>
> SELECT sales * cost AS total WHERE total > 100
>
> Instead, you need to say:
>
> SELECT sales * cost AS total WHERE sales * cost > 100
>
>
> I'm just curious WHY you can't do it. You can, for example, specify ORDER
> BY total.
>
> I can't think of any reason why it would be either difficult or ambiguous
> for the SQL engine to allow you to use your calculated field name in the
> WHERE part of the query.
>
> If someone can give me a good reason why this is so, it will stop it
> annoying me so much.
>
> Regards ... Ross
> .
> . Ross Honniball. JCU Bookshop Cairns, Qld, Australia.
> .
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>