P
P
Peter2022-04-13 20:41:49
MySQL
Peter, 2022-04-13 20:41:49

How to search by JSON type field?

There is a data type:

there is a JSON field employees in the following format: [
{
"id": 1,
"name": "Garina Irina Petrovna"
},

{
"id": 2,
"name": "Ivanov Ivan Ivanovich"
}

]

SELECT 
  *
FROM 
  `items`
WHERE 
    `employees`->>"$.id"= 1


no result(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Petr, 2022-04-13
Petersky @MOtoroller1983

Solution:
SELECT * FROM `items`
WHERE
JSON_CONTAINS(employees, JSON_OBJECT('id', 1))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question