469,898 Members | 1,729 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Column Alias and HAVING clause

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

Apr 7 '06 #1
2 8983
>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
Apr 7 '06 #2
sa*********@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.
Apr 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by muzamil | last post: by
12 posts views Thread by yoyo | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.