Skip to main content
Known Participant
July 8, 2008
Question

SQL Question Using As Clause

  • July 8, 2008
  • 3 replies
  • 477 views
I using the AS clause to define 'myZip' as seen below, but am unable to use the WHERE clause using the defined column. This is a scaled down version of what I am trying to do but will sufice as an example:

SELECT npp_users.ZIP as myZip
FROM users
WHERE myZip = `00010`

Anyone have any clues?

Thanks
This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

Inspiring
July 9, 2008
SELECT npp_users.ZIP [myZip]
FROM users
WHERE npp_users.ZIP = `00010`


"VernMan" <webforumsuser@macromedia.com> wrote in message
news:g50s5b$c52$1@forums.macromedia.com...
>I using the AS clause to define 'myZip' as seen below, but am unable to use
>the
> WHERE clause using the defined column. This is a scaled down version of
> what I
> am trying to do but will sufice as an example:
>
> SELECT npp_users.ZIP as myZip
> FROM users
> WHERE myZip = `00010`
>
> Anyone have any clues?
>
> Thanks
>


Inspiring
July 9, 2008
.oO(Michael White)

>VernMan wrote:
>> I using the AS clause to define 'myZip' as seen below, but am unable to use the
>> WHERE clause using the defined column. This is a scaled down version of what I
>> am trying to do but will sufice as an example:
>>
>> SELECT npp_users.ZIP as myZip
>> FROM users
>> WHERE myZip = `00010`
>>
>> Anyone have any clues?
>>
>
>WHERE myZip = "00010"

Nope. The correct delimiter for strings in SQL is the single quote
(assuming that the ZIP code is stored as a string - as a numeric even
the single quotes would be wrong).

The problem here is that you can't use alias names in a WHERE clause.
You either have to use the same expression as in the SELECT part (here:
npp_users.ZIP) or a HAVING clause.

B.1.5.4. Problems with Column Aliases
http://dev.mysql.com/doc/refman/5.0/en/problems-with-alias.html

Micha
Inspiring
July 8, 2008
VernMan wrote:
> I using the AS clause to define 'myZip' as seen below, but am unable to use the
> WHERE clause using the defined column. This is a scaled down version of what I
> am trying to do but will sufice as an example:
>
> SELECT npp_users.ZIP as myZip
> FROM users
> WHERE myZip = `00010`
>
> Anyone have any clues?
>

WHERE myZip = "00010"

Mick