The question is about MySQL/MariaDB JSON Functions.
How do you find intersection of multiple JSON structures?
In PHP it is done using this code:
array_intersect(
['a', 'b'],
['b', 'c']
);
If we imagine a function named JSON_INTERSECT, the code would look like this:
SET @json1 = '{"key1": "a", "key2": "b"}';
SET @json2 = '["b", "c"]';
SET @json3 = '["c", "d"]';
SELECT JSON_INTERSECT(@json1, @json2); // returns '["b"]';
SELECT JSON_INTERSECT(@json1, @json3); // returns NULL;
解决方案
It looks there are no good built-in ways of doing this and there are still no good answers on this topic, so I thought I'd add my