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 query did NOT work.
SELECT *
FROM `minto_regsix_session`
WHERE JSON_CONTAINS(`day`, '2') = 1
The correct query requires including the double quotes from the array within the query.
SELECT *
FROM `minto_regsix_session`
WHERE JSON_CONTAINS(`day`, '"2"');
Originally posted and answered on Stack Exchange.
https://stackoverflow.com/questions/61868619/using-json-contains-in-mysql-query-gets-not-result
Here's an example SELECT statement to extract JSON data.
SELECT `id`, JSON_EXTRACT(`params`, "$.start_date"), JSON_EXTRACT(`params`, "$.end_date"), JSON_EXTRACT(`params`, "$.early_bird_date"), JSON_EXTRACT(`params`, "$.end_date"), JSON_EXTRACT(`params`, "$.prorate_date"), JSON_EXTRACT(`params`, "$.allow_prorate") FROM `minto_categories` WHERE `id` = 110