1

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.

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

Atype is defined as VARCHAR.
I see it works with VARCHAR too. I updated the DBFiddel. :)
Invalid JSON text in argument 1 to function json_extract: "Invalid value." Getting this error.
Did you find a corrispondence between your table definition and data insert with my DBFiddle? Which version of Mysql are you using?
what if data in column is like this {"Domain_Name": ["www.fb.com"], "attack": [false], "Probability": [0.001]}
0

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]';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.