> >Is this a bug?  I can't find an answer to this question in FAQs or archives.
> >
> >CREATE TABLE aa ( a int);
> >INSERT INTO aa VALUES (1),(2),(3),(2),(4),(5),(1),(6),(3);
> >
> >the following :
> >mysql> select a,count(*) as z from aa where z>1 group by a;
> >
> >displays this error:
> >ERROR 1054: Unknown column 'z' in 'where clause'
> >
> >Why isn't z recognized as a column identifier?
>
> As others have pointed out, your query requires a HAVING rather than a
> WHERE.  What hasn't been pointed out, which is worth knowing, is that
> column aliases cannot be used in *any* WHERE clause.

...because the WHERE clause is processed first, and the SELECT evaluated later.
Similarly GROUP BY is processed before HAVING (which is why that suggestion works).

Somewhere there's a 'table' or list showing the sequence that the various clauses are 
evaluated/executed. Is it
in the manual or in your book Paul? If it's online, it would be useful to know where 
so that a link can be added
to answers to such questions...

Anyone remember where?
=dn



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to