0

I'm having some real trouble running some basic queries that I should be able to run easily.

I have a table called settings. When I query SELECT * FROM settings I get the output:

+----+-----------------+--------------------------------+
| ID | key             | value                          |
+----+-----------------+--------------------------------+
|  1 | view            | default                        |
|  2 | sitename        | value!                    |
|  3 | siteurl         |                                |
|  4 | captcha.enabled | 0                              |
|  5 | upload_path     | http://web/uploads |
+----+-----------------+--------------------------------+

However, when I then run the simply query SELECT key FROM settings WHERE ID > 0 I get an error!

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key from settings where ID > 0' at line 1
mysql>"

If I wrap key in single quotes, to make: SELECT 'key' FROM settings WHERE ID > 0 I get:

+-----+
| key |
+-----+
| key |
| key |
| key |
| key |
| key |
+-----+

So for the life of me I cannot understand why mySQL won't recognise the column name! The same thing happens for every column name as well, not just key.

If anyone knows what's going on here please let me know.

2
Contributors
2
Replies
14
Views
1 Year
Discussion Span
Last Post by James_43
1

Key is a reserved word in MySQL. You need to use back ticks to escape it rather than quotes.
Backticks are the key to the left of the 1 on most keyboards, with the tilde character: ~ as the shift option.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.