Sachin Vairagi
Sachin Vairagi

Reputation: 5334

MySQL - how to match JSON string in where condition?

I am using MySQL 5.6 , one of my table field contains JSON data. I am getting syntax error when using below query -

SELECT * FROM products WHERE device_id = '1212'and product_id = '54'and option = '"{"229":"20"}"'

field option has value as {"229":"20"} I am getting 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 'option = '"{"229":"20"}"'
LIMIT 0, 25' at line 1 

Please suggest any solution , thanks much!!!

Upvotes: 0

Views: 284

Answers (1)

juergen d
juergen d

Reputation: 204746

option is a reserved keyword in MySQL. Use backticks to escape it or choose a different name

... `option` = ...

Upvotes: 5

Related Questions