Hello can anyone tell me why this query works
SELECT username AS 'User' FROM users WHERE username='blah'
but this will not
SELECT username AS 'User' FROM users WHERE 'User'='blah'
thanks, chuck
Use back-quotes for the quoting of column/table names and aliases:
SELECT username AS `User` FROM users WHERE `User`='blah'
Or to be on the completely safe side:
SELECT `username` AS `User` FROM `users` WHERE `User`='blah'
Thanks for your reply,
I used your completely safe side query but I get this error message however
Unknown column 'User' in 'where clause'
I forgot about the fact that column aliases cannot be used in a where clause:
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.