I am looking for a way of find rows by given element of the json table that match the pattern.
Lets start with mysql table:
CREATE TABLE `person` (
`attributes` json DEFAULT NULL
);
INSERT INTO `person` (`attributes`)
VALUES ('[{"scores": 1, "name": "John"},{"scores": 1, "name": "Adam"}]');
INSERT INTO `person` (`attributes`)
VALUES ('[{"scores": 1, "name": "Johny"}]');
INSERT INTO `person` (`attributes`)
VALUES ('[{"scores": 1, "name": "Peter"}]');
How to find all records where attributes[*].name consists John*
pattern?
In the John*
case the query should return 2 records (with John and Johny).
2
Answers
https://sqlize.online/sql/mysql80/c9e4a3ffa159c4be8c761d696e06d946/
https://sqlize.online/s/P4
or
https://sqlize.online/s/b4