Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

SQL Question Using As Clause

Explorer ,
Jul 08, 2008 Jul 08, 2008
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
TOPICS
Server side applications
451
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 08, 2008 Jul 08, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 08, 2008 Jul 08, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 09, 2008 Jul 09, 2008
LATEST
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
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines