0

I have the following sql query:

SELECT * from data where key="test"

When I run it the phpmyadmin give me the following error

#1064 - 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="test" LIMIT 0, 30' at line 1

The type of the key column is varchar(150)

amrswalha
  • 372
  • 8
  • 20

3 Answers3

3
SELECT * from data where `key`="test"

You shouldn't name your columns as any of the reserved words. OR at least escape them with backticks (``) in your queries when you do.

Shef
  • 44,808
  • 15
  • 79
  • 90
3

In MySQL Key is reserved word. So surround your column name with backticks (`) character. Also there is no difference between single quote and double quotes in MySQL.

SELECT * from data where `key`='test';
SELECT * from data where `key`="test";
MilanPanchal
  • 2,943
  • 1
  • 19
  • 37
3

key is a reserved word in MySQL, You need to quote it with backticks

SELECT * from data where `key`="test"

Here is the complete list of reserved words

exussum
  • 18,275
  • 8
  • 32
  • 65