Column Alias and HAVING clause
am 07.04.2006 19:01:16 von sanderson82
Hi
I am having problems with the HAVING clause. I know it can use aliases
but the alias I am using has a space in it, eg 'Device ID'
My querry looks like (simplified, devID is a calculation)
SELECT devID AS 'Device ID' FROM tblDevice HAVING 'Device ID' = '123'
and it does not work
but if I use
SELECT devID AS 'Device_ID' FROM tblDevice HAVING Device_ID = '123'
everything works.
How can I use an alias that contains a space in the HAVING clause?
Thanks
Steve
Re: Column Alias and HAVING clause
am 07.04.2006 20:03:44 von Bill Karwin
sanderson82@gmail.com wrote:
> How can I use an alias that contains a space in the HAVING clause?
MySQL uses back-ticks `` as the default identifier delimiter.
Try this:
SELECT devID AS `Device ID` FROM tblDevice HAVING `Device ID` = '123'
Regards,
Bill K.
Re: Column Alias and HAVING clause
am 07.04.2006 20:06:38 von gordonb.gxs24
>I am having problems with the HAVING clause. I know it can use aliases
>but the alias I am using has a space in it, eg 'Device ID'
*WHY* does the alias have a space in it?
Use backquotes, not single quotes, to quote field names.
Use single quotes, not backquotes, to quote strings.
>My querry looks like (simplified, devID is a calculation)
>
>SELECT devID AS 'Device ID' FROM tblDevice HAVING 'Device ID' = '123'
SELECT devID AS `Device ID` FROM tblDevice HAVING `Device ID` = '123'
Gordon L. Burditt