However, you can use HAVING. HAVING is post-processed, in a brute force
method (no indexes can be used).
Select invno, invdate, invamt, left(invdate,2) as month from
salesfile HAVING month = '01'
But I would use Roger's example since it can take advantage of indexes.
Regards,
Erik Osterman
-----Original Message-----
From: Roger Baklund [mailto:[EMAIL PROTECTED]
Sent: Sunday, November 09, 2003 6:59 AM
To: [EMAIL PROTECTED]
Cc: David Katz
Subject: Re: Aliases
* David Katz
> I am trying to do a select statement where I am using one of the
> aliases in the where clause. I keep getting an error that the field
> does not exist.
>From the manual: "Note that standard SQL doesn't allow you to refer to an
alias in a WHERE clause. This is because when the WHERE code is executed the
column value may not yet be determined."
<URL: http://www.mysql.com/doc/en/Problems_with_alias.html >
> example:
>
> Select invno, invdate, invamt, left(invdate,2) as month from
> salesfile where
> month = '01'
>
> MySql keeps telling me that month is not a field. Is there a way to do
> this?
Yes, simply repeat the expression:
Select invno, invdate, invamt, left(invdate,2) as month
from salesfile
where left(invdate,2) = '01'
--
Roger
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]