F
F
flafy42019-10-28 16:20:55
Laravel
flafy4, 2019-10-28 16:20:55

How to find records in a table among JSON arrays?

Hello! There is such a record in the database:
5db6eab313c66342964353.png
How can I select all records that have either 0or or in 1 element3
{"1":["0", "3"]..."3":[....]}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
ggbb, 2019-10-28
@ggbb

If the database is mysql, you can query the database with JSON_EXTRACT.
But if there is a lot of data in the table, it is better to pull out the filters field into a separate table.
Working with json in mysql
https://dev.mysql.com/doc/refman/8.0/en/json-funct...

A
Alexander, 2019-10-28
@AleksandrB

MySQL 8.0 can be used for this

S
Sergey c0re, 2019-10-30
@erge

select *
  from tbl
  where JSON_CONTAINS(filters, '{"1":["0"]}') = 1
     OR JSON_CONTAINS(filters, '{"1":["3"]}') = 1

example on dbfiddle
works since MySQL 5.7

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question