2

I have saved the json data in mysql database column which looks like below

[{"one":"mg road plot number 711 xyz"},{"two":"dc road plot number 711 xyz"}]

json data like above is being stored for all the records with different address. So what I am trying to do is , I want to search all the customer who are having address of mg road.

So I have tried JSON_SEARCH and JSON_CONTAINS but it always returning me no records found even though there are 2 records in a table. So where I am going wrong.

SELECT * FROM `tbl_clients_data` WHERE JSON_SEARCH(reci_address,'all', "mg road")


SELECT * FROM `tbl_clients_data` WHERE JSON_CONTAINS(reci_address, 'mg road', '$.one')

1 Answer 1

1

Just try this code:

SELECT * FROM `tbl_clients_data` WHERE JSON_EXTRACT(reci_address, '$[*].one') 
LIKE 'mg road%' OR JSON_EXTRACT(reci_address, '$[*].two') LIKE 'mg road%'

JSON_EXTRACT Extracts data from a JSON document. The extracted data is selected from the parts matching the path arguments. Returns all matched values; either as a single matched value, or, if the arguments could return multiple values, a result autowrapped as an array in the matching order.

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

4 Comments

i just tried it returns 0 rows and shows error like ===Warning: #4038 Syntax error in JSON text in argument 1 to function 'json_extract' at position 31
it;s still the same with 0 rows and same warning/error
The error should have not been there , here is a reference to that error stackoverflow.com/questions/35735454/…
thank you for the link..but still its giving empty result,,

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.