SyntaxStudy
Sign Up
MySQL JSON_OVERLAPS and JSON_CONTAINS_PATH
MySQL Advanced 4 min read

JSON_OVERLAPS and JSON_CONTAINS_PATH

JSON_OVERLAPS

JSON_OVERLAPS() (MySQL 8.0.17+) returns true if two JSON documents share any elements. JSON_CONTAINS_PATH() checks whether a path exists.

Example
-- Check if any tag matches
SELECT * FROM articles
WHERE JSON_OVERLAPS(tags, '["php", "mysql"]');

-- Check if a path exists
SELECT JSON_CONTAINS_PATH(
  '{"a": {"b": 1}}',
  'one',
  '$.a.b'
);  -- 1 (true)
Pro Tip

JSON_OVERLAPS is great for tag/category intersection queries.