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

SQL Question Using As Clause

Explorer ,
Jul 08, 2008 Jul 08, 2008

Copy link to clipboard

Copied

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

Views

446
Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Report

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

Copy link to clipboard

Copied

.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

Votes

Translate

Report

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

Copy link to clipboard

Copied

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
>


Votes

Translate

Report

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