0

column contain value given below.


 [
  {
    "bActive": false,
    "sSubLocation": "",
    "aiSeries": [],
    "iUser": "1"
  },
  {
    "bActive": true,
    "sSubLocation": "Mytestcase",
    "aiSeries": [],
    "iUser": "1"
  }
]

I want to get result as sSubLocation key where it have bActive =true and sSubLocation = "Mytestcase";

3
  • 2
    Don't use JSON to store data you need to query on, particularly where you have multi-dimensional arrays. Create proper tables for the data. The query for this would be trivial if you'd set up your tables properly. Commented May 19, 2021 at 3:30
  • Parse (use JSON_TABLE function) then query to separate values. Commented May 19, 2021 at 5:25
  • * i want to get result as sSubLocation key where it have bActive =true and sSubLocation = "Mytestcase";* ??? Commented May 19, 2021 at 5:30

1 Answer 1

1
SELECT test.id, jsontable.*
FROM test
CROSS JOIN JSON_TABLE(test.value,
                      '$[*]' COLUMNS (bActive BOOLEAN PATH '$.bActive',
                                      sSubLocation VARCHAR(255) PATH '$.sSubLocation',
                                      aiSeries JSON PATH '$.aiSeries',
                                      iUser VARCHAR(255) PATH '$.iUser')) jsontable
HAVING bActive = true 
   AND sSubLocation = 'Mytestcase'

https://dbfiddle.uk/?rdbms=mysql_8.0&fiddle=bcf7f238e23a2c282cdea76c183ae8fa

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

3 Comments

This seems not working on Mysql Version 5.7.4.
Thanks Akina, but it have error : 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 '(test.value, '$[*]' COLUMNS (bActive BOOLEAN PATH '$.bActi' at line 3.
@amitchauhan Maybe your MySQL version is too ancient? you have not specified it..

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.