I came across a couple of days that I can't solve. I know the basic MySql but I was trying to work with SELECTs to recover data in JSON.
I have a table in the database called home_slider.
Inside I have the following columns:
id_shop, id_lang, id_image and json_groups_id.
They are all INT fields except json_groups_id where I insert files via json_econde.
The JSON in the "json_groups_id" field is structured like this:
{"2": "Guest", "3": "Customer", "4": "Custom"}
All these data are saved in a simple form.
In the end I find myself different are similar to this:
+------------+----------------+-----------------+-------------------------------+
| shop_id | id_lang | id_image | json_groups_id |
+------------+----------------+-----------------+--------------------------------+
| 1 | 1 | 2 | {"2": "Guest", "3": "Customer"} |
| 1 | 1 | 3 | {"1": "Visit", "4": "Other"} |
| 1 | 1 | 4 | {"2": "Guest", "5": "Test"}
+-------------+----------------+-----------------+--------------------------------+
The problem arrives now, given an array similar to this [2,5,4]
.
I would like to retrieve all the rows that in the "json_groups_id" field have that key.
I tried whith JSON_EXTRACT but I couldn't do it.
What kind of select can I use?
Thanks
Mario