How can write queries in MySQL that can parse JSON data in a column?

后端 未结 3 504
庸人自扰
庸人自扰 2020-12-01 11:55

I have a table in MySQL that has a column that store JSON objects. How can I easily run queries that can have some of the JSON fields in the WHERE clause?

EX: Wi

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 12:27

    You could use json_extract (5.7 up). https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-extract

    SELECT user_id, json_data
    FROM articles 
    WHERE json_extract(json_data, '$.title') LIKE '%CPU%';
    

提交回复
热议问题