title: How to emulate JSON_OVERLAPS function on MySQL 5.7?
body: <p>I have two columns from different tables that hold JSON-formatted data. The data stored in both columns are arrays. Example:</p>
  
  <p><strong><code>users</code></strong></p>
  
  <pre><code>+----+------------------+
  | id | options          |
  +----+------------------+
  |  1 | ["AB","CD","XY"] |
  |  2 | ["CD","GH"]      |
  +----+------------------+
  </code></pre>
  
  <p><strong><code>items</code></strong></p>
  
  <pre><code>+----+-------------+
  | id | options     |
  +----+-------------+
  | 10 | ["CD","EF"] |
  | 11 | ["GH","XY"] |
  | 12 | ["GH"]      |
  +----+-------------+
  </code></pre>
  
  <p>I wanted to write a query that returns all the rows from <code>users</code> which matches a given row from <code>items</code>, using <code>options</code> columns to perform the match. The rule is if any value in the array is present in both rows, they are a match. Example: user 1 would match items 10 (because of <code>CD</code> option) and 11 (because of <code>XY</code> option); user 2 would match items 10, 11 and 12 because all of them have <code>CD</code> or <code>GH</code>.</p>
  
  <p>Looking at MySQL docs I found that <a href="https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-overlaps" rel="nofollow noreferrer"><code>JSON_OVERLAPS</code></a> does exactly that. However, I'm running MySQL 5.7 and the function is only available starting at 8.0.17. There is also no much talking around this function on the web.</p>
  
  <p>How could I emulate <code>JSON_OVERLAPS</code> behavior on MySQL 5.7 in a query?</p>
  
  <p><strong>Edit</strong>: Unfortunately, upgrading to MySQL 8 is not an option since we run MariaDB on production, which also doesn't have that function.</p>