tandheel
tandheel

Reputation: 19

Mysql where clause query on json column has array value

I have following records in my DB.

table= defense

id   Atype
1   {"Domain_name":www.pgmobile.com , "attack": true, "probability": "9.53"}
2   {"Domain_name":www.fb.com , "attack": false , "probability": "3.35"}
3   {"Domain_name":www.pub.com , "attack": true, "probability": "8.34"}

I want to make where clause condition on Atype column. Where in column Atype attack is true...

e.g: select * from defense where attack= true // here some help needed

thanks for help.

Upvotes: 1

Views: 58

Answers (2)

ammalik
ammalik

Reputation: 50

For {"Domain_Name": ["www.fb.com"], "attack": [false], "Probability": [0.001]}

query wil be use 'like'

SELECT *
FROM defense
WHERE JSON_EXTRACT(Atype, '$.attack') LIKE '[false]';

Upvotes: 0

Ma3x
Ma3x

Reputation: 535

If your Atype is defined as JSON in your table, you can use this query:

SELECT *
FROM defense
WHERE JSON_EXTRACT(Atype, '$.attack') = true;

as you can see from this DBFiddle

Upvotes: 1

Related Questions