TheHvidsten
TheHvidsten

Reputation: 4448

Find value from an array in a MySQL JSON column

I have the following table contents

ID (int) | ArrayValues (JSON)
-----------------------------
1        | [7,13,15]
2        | [4,8,12]
3        | [15,16,23]

I want to get all the rows that contain i.e. 15 in the ArrayValues (row 1 and 3) so I use this query:

SELECT *
FROM MyTable T
WHERE 15 IN
(
    SELECT A.Value
    FROM JSON_TABLE
    (
        T.ArrayValues,
        '$[*]' COLUMNS
        (
            Value INT PATH '$[0]'
        )
    ) AS A
)

This, however, returns zero rows.

How can I get it to return what I expect? What is wrong with my query?

Upvotes: 0

Views: 14

Answers (0)

Related Questions