2

I want a query to return all the fields for all the entries in the table minto_regsix_session that include a value of 2 in the 'day' field. Following is a screenshot from phpMyAdmin of the table including the day field which contains a JSON array.

This is the data in the MySQL table

This is the mysql query I'm using:

SELECT * 
FROM `minto_regsix_session` 
WHERE JSON_CONTAINS(`day`, '2') = 1

The query returns an empty result. I would expect it to return the data from lines 2, 4, and 5. Why doesn't this work?

1 Answer 1

2
SELECT * 
FROM `minto_regsix_session` 
WHERE JSON_CONTAINS(`day`, '"2"');
Sign up to request clarification or add additional context in comments.

8 Comments

Thank you so much. It's so obvious when I see it but it never occurred to me at the time. I tried double quotes and single quotes and no quotes but I'm new to JSON and it didn't occur to me that I need to include the double quotes inside the single quotes. Much appreciated.
@user3765165 As documentation claims both arguments must be "valid JSON document". '2' is NOT valid JSON...
how to search for multiple values here?
@CuriousDeveloper Depends on the task. It can be "at least one is present" or "none is absent".
@Akina I have similar table as above in question. I want to search the value in any array for example if input is 1,2 then all row which contain both 1 & 2 or any of them.
|

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.