By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE Users (
id INT,
interestIds JSON
);
INSERT INTO Users VALUES
(1, "[1, 2]"),
(2, "[3, 2]"),
(3, "[2, 4]"),
(3, "[3, 4]");
SELECT *
FROM Users
WHERE JSON_CONTAINS(interestIds, '2') = 1;
id | interestIds |
---|---|
1 | [1, 2] |
2 | [3, 2] |
3 | [2, 4] |
-- example using the third parameter.
SELECT *
FROM Users
WHERE JSON_CONTAINS(interestIds, '2', '$[1]') = 1;
id | interestIds |
---|---|
1 | [1, 2] |
2 | [3, 2] |