WHERE and 'AS' problem

This is a discussion on WHERE and 'AS' problem within the MySQL Database forums, part of the Database Forums category; SELECT * , DATE_ADD( test_equipment_cal_date, INTERVAL test_equipment_cal_days DAY ) AS test_equipment_expire_date FROM `test_equipment` WHERE test_equipment_expire_date < '2008-01-31' #1054 - Unknown column 'test_equipment_expire_date' ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-31-2008
Geoff
 
Posts: n/a
Default WHERE and 'AS' problem

SELECT * , DATE_ADD( test_equipment_cal_date, INTERVAL
test_equipment_cal_days DAY ) AS test_equipment_expire_date
FROM `test_equipment`
WHERE test_equipment_expire_date < '2008-01-31'

#1054 - Unknown column 'test_equipment_expire_date' in 'where clause'

so, i simply can't do that ???
how am i supposed to do such a thing ?
Reply With Quote
  #2 (permalink)  
Old 01-31-2008
Captain Paralytic
 
Posts: n/a
Default Re: WHERE and 'AS' problem

On 31 Jan, 10:29, Geoff <foooooo...@hotmail.com> wrote:
> SELECT * , DATE_ADD( test_equipment_cal_date, INTERVAL
> test_equipment_cal_days DAY ) AS test_equipment_expire_date
> FROM `test_equipment`
> WHERE test_equipment_expire_date < '2008-01-31'
>
> #1054 - Unknown column 'test_equipment_expire_date' in 'where clause'
>
> so, i simply can't do that ???
> how am i supposed to do such a thing ?


Put it in the HAVING clause instead
Reply With Quote
  #3 (permalink)  
Old 01-31-2008
Geoff
 
Posts: n/a
Default Re: WHERE and 'AS' problem

Captain Paralytic wrote:
> On 31 Jan, 10:29, Geoff <foooooo...@hotmail.com> wrote:
>> SELECT * , DATE_ADD( test_equipment_cal_date, INTERVAL
>> test_equipment_cal_days DAY ) AS test_equipment_expire_date
>> FROM `test_equipment`
>> WHERE test_equipment_expire_date < '2008-01-31'
>>
>> #1054 - Unknown column 'test_equipment_expire_date' in 'where clause'
>>
>> so, i simply can't do that ???
>> how am i supposed to do such a thing ?

>
> Put it in the HAVING clause instead


nice one :)

was the first thing that came to mind
i though you used that with group by only though

got it working :)
Reply With Quote
  #4 (permalink)  
Old 01-31-2008
Captain Paralytic
 
Posts: n/a
Default Re: WHERE and 'AS' problem

On 31 Jan, 11:13, Geoff <foooooo...@hotmail.com> wrote:
> Captain Paralytic wrote:
> > On 31 Jan, 10:29, Geoff <foooooo...@hotmail.com> wrote:
> >> SELECT * , DATE_ADD( test_equipment_cal_date, INTERVAL
> >> test_equipment_cal_days DAY ) AS test_equipment_expire_date
> >> FROM `test_equipment`
> >> WHERE test_equipment_expire_date < '2008-01-31'

>
> >> #1054 - Unknown column 'test_equipment_expire_date' in 'where clause'

>
> >> so, i simply can't do that ???
> >> how am i supposed to do such a thing ?

>
> > Put it in the HAVING clause instead

>
> nice one :)
>
> was the first thing that came to mind
> i though you used that with group by only though
>
> got it working :)

There's a paragraph about MySQL's particular implementation of HAVING
on this page:

http://dev.mysql.com/doc/refman/5.0/en/select.html
Reply With Quote
  #5 (permalink)  
Old 01-31-2008
Jerry Stuckle
 
Posts: n/a
Default Re: WHERE and 'AS' problem

Geoff wrote:
> Captain Paralytic wrote:
>> On 31 Jan, 10:29, Geoff <foooooo...@hotmail.com> wrote:
>>> SELECT * , DATE_ADD( test_equipment_cal_date, INTERVAL
>>> test_equipment_cal_days DAY ) AS test_equipment_expire_date
>>> FROM `test_equipment`
>>> WHERE test_equipment_expire_date < '2008-01-31'
>>>
>>> #1054 - Unknown column 'test_equipment_expire_date' in 'where clause'
>>>
>>> so, i simply can't do that ???
>>> how am i supposed to do such a thing ?

>>
>> Put it in the HAVING clause instead

>
> nice one :)
>
> was the first thing that came to mind
> i though you used that with group by only though
>
> got it working :)
>


That is true in ANSI SQL. MySQL extends that functionality.

Personally, I wish ANSI would pick up on MySQL's way of doing things. I
see no logical reason for the restriction, and the syntax can be very handy.

Otherwise you have to repeat the entire calculated expression in the
WHERE clause. A good optimizer should recognize that, but who knows?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
  #6 (permalink)  
Old 01-31-2008
Luuk
 
Posts: n/a
Default Re: WHERE and 'AS' problem


"Jerry Stuckle" <jstucklex@attglobal.net> schreef in bericht
news:eOednZcnMt7jWDzanZ2dnUVZ_ournZ2d@comcast.com. ..
> Geoff wrote:
>> Captain Paralytic wrote:
>>> On 31 Jan, 10:29, Geoff <foooooo...@hotmail.com> wrote:
>>>> SELECT * , DATE_ADD( test_equipment_cal_date, INTERVAL
>>>> test_equipment_cal_days DAY ) AS test_equipment_expire_date
>>>> FROM `test_equipment`
>>>> WHERE test_equipment_expire_date < '2008-01-31'
>>>>
>>>> #1054 - Unknown column 'test_equipment_expire_date' in 'where clause'
>>>>
>>>> so, i simply can't do that ???
>>>> how am i supposed to do such a thing ?
>>>
>>> Put it in the HAVING clause instead

>>
>> nice one :)
>>
>> was the first thing that came to mind
>> i though you used that with group by only though
>>
>> got it working :)
>>

>
> That is true in ANSI SQL. MySQL extends that functionality.
>
> Personally, I wish ANSI would pick up on MySQL's way of doing things. I
> see no logical reason for the restriction, and the syntax can be very
> handy.
>
> Otherwise you have to repeat the entire calculated expression in the WHERE
> clause. A good optimizer should recognize that, but who knows?
>


the disadvantage of some people writing

SELECT name FROM persons HAVING name='Santa';

will stop this from becoming ANSI, i guess.....



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:42 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0