I have a row in table A of JSON array of integers.
I have a table B whose rows have a field of a (possibly empty) JSON array of objects, and each object has a 'parent' field.
table A
+-----------+
| foo |
+-----------+
| [1, 2] |
+-----------+
table B
+--------------------------------+
| bar |
+--------------------------------+
| [{"parent": 1}] |
| [{"parent": 2}, {"parent": 3}] |
| [{"parent": 4}] |
| [] |
+--------------------------------+
How do I get the rows from table B whose objects in bar don't have any parent matching any element in foo? i.e. the last 2 rows here should be returned.
I tried doing something with SELECT JSON_EXTRACT(bar, '$[*].parent') FROM B, but the result is a JSON array
+-----------------------------------------+
| SELECT JSON_EXTRACT(bar, '$[*].parent') |
+-----------------------------------------+
| [1] |
| [2, 3] |
| [4] |
| NULL |
+-----------------------------------------+
and the function JSON_CONTAINS() doesn't return partial matches:
"A candidate array is contained in a target array if and only if every element in the candidate is contained in some element of the target." MySQL docs
Any help is greatly appreciated. MySQL version 5.7.22