472,102 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,102 software developers and data experts.

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 9099
>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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.