Tampa
Tampa

Reputation: 78372

How to query with a where clause in mysql json table

I am using mysql 5.7.x

I can create a mysql json table

 CREATE TABLE t1 (jdoc JSON);

I can insert rows.

INSERT INTO t1 VALUES('{"key1": "value1", "key2": "value2"}');
INSERT INTO t1 VALUES('{"key1": "value11", "key2": "value22"}');

I can also get all rows:

SELECT * from t1;

How do I use a where clause?

select * from t1 where "key1" = "value1"

Upvotes: 8

Views: 22220

Answers (1)

Sterls
Sterls

Reputation: 761

You can try:

SELECT *
FROM t1
WHERE json_extract(jdoc, '$.key1')='value1'

Upvotes: 22

Related Questions