.oO(David Powers)
>Michael Fesser wrote:
>> Just a little thing: The WHERE wouldn't work here.
>
>Ah, the dangers of writing answers without first testing
them. Thanks
>for pointing that out, Micha.
>
>> SELECT ..
>> FROM ...
>> WHERE CONCAT_WS(' ', firstname, lastname) LIKE ...
>
>Actually, my first instinct was to do it that way. Maybe
I should stick
>with my instincts. ;-)
Good idea. ;)
>> SELECT ..
>> FROM ...
>> HAVING fullname LIKE ...
>
>Not familiar with HAVING. Time to get my MySQL books out
again to brush
>up on less frequently used parts of the syntax.
There's a short note about this issue in the manual:
| Standard SQL doesn't allow you to refer to a column alias
in a WHERE
| clause. This restriction is imposed because when the WHERE
code is
| executed, the column value may not yet be determined. For
example, the
| following query is illegal:
|
| SELECT id, COUNT(*) AS cnt FROM tbl_name WHERE cnt > 0
GROUP BY id;
|
| The WHERE statement is executed to determine which rows
should be
| included in the GROUP BY part, whereas HAVING is used to
decide which
| rows from the result set should be used.
http://dev.mysql.com/doc/refman/5.0/en/problems-with-alias.html
There are also some important hints and notes about HAVING in
the SELECT
chapter, because some of its behaviour is MySQL-specific.
http://dev.mysql.com/doc/refman/5.0/en/select.html
Micha