Keywords as column names.

I was doing work on one of my contracts when I came across an error message that was just not going away. What I was doing was selecting rows from a ‘users’ table where the ‘desc’ column = ‘yes’. So the query goes: select * from users where desc=’yes’; or so I thought. Since it had been a while since doing MySQL, I was trying to do quick fixes which were not working. Later on, I realized that ‘desc’ was a MySQL keyword, and then put the quotes ‘desc’ in the query (which was not done initially). However, this still did not work. After a few tries, I got the real syntax to use for the query, and here it is: select * from users where `desc`=’yes’.

If you noticed, the quotes is not the single quote used, but the `, i.e. the one with the tilde key (~).  Anyways, now my code is working, and everything looks good. Cheers.


Thinking about someting? Leave a Reply...

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s