Reputation: 9
id | lessons |
---|---|
1 | ["3M-232","3M-313"] |
2 | ["3M-311","3M-312"] |
3 | ["3M-443","3M-565"] |
4 | ["4M-232","4M-313"] |
5 | ["4M-311","4M-312"] |
6 | ["4M-443","4M-565"] |
How can get rows that match lessons with "3M-232" as one of them
SELECT * FROM merged_lesson where lessons = "3M-232";
Expected only row 1 to be returned
originally posted as image
Upvotes: 0
Views: 86
Reputation: 9201
We can use JSON_CONTAINS function:
SELECT id, JSON_PRETTY(lessons) AS lessons
FROM tbl_name
WHERE JSON_CONTAINS(lessons, '"3M-232"')
Or, as pointed out by @lemon (ref), it would be much faster to use MEMBER OF
:
SELECT id, JSON_PRETTY(lessons) AS lessons
FROM tbl_name
WHERE '3M-232' MEMBER OF(lessons)
Upvotes: 4