Using MySQL JSON field to join on a table
<p>I have a json field that stores a list of ids (not best practice here I know), I want to know if it's possible to use do operations on this JSON field and use them in the sql.</p>

<p>Below is a fictitious example of what I'm trying to achieve, is something like this doable? </p>

<pre><code>CREATE TABLE user (
    user_id INT,
    user_name VARCHAR(50),
    user_groups JSON
);

CREATE TABLE user_group (
    user_group_id INT,
    group_name VARCHAR(50)
);

INSERT INTO user_group (user_group_id, group_name) VALUES (1, 'Group A');
INSERT INTO user_group (user_group_id, group_name) VALUES (2, 'Group B');
INSERT INTO user_group (user_group_id, group_name) VALUES (3, 'Group C');

INSERT INTO user (user_id, user_name, user_groups) VALUES (101, 'John', '[1,3]');
</code></pre>

<p>With the above data I would like to fashion a query that gives me the results like this:</p>

<pre><code>user_id | user_name | user_group_id | group_name|
-------------------------------------------------
101     | John      | 1             | Group A
101     | John      | 3             | Group C
</code></pre>

<p>Some psuedo style SQL I'm thinking is below, though I still have no clue if this is possible, or what JSON functions mysql offers I would use to achieve this</p>

<pre><code> SELECT 
       u.user_id, 
       u.user_name, 
       g.user_group_id
       g.group_name
   FROM users u
   LEFT JOIN user_group g on g.user_group_id in some_json_function?(u.user_groups)
</code></pre>

<p>Let me know if the question isn't clear.</p>