Using MySQL JSON field to join on a table

后端 未结 3 719
盖世英雄少女心
盖世英雄少女心 2020-11-30 08:27

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 s

3条回答
  •  無奈伤痛
    2020-11-30 08:54

    With the help of Feras's comment and some fiddling:

      SELECT 
           u.user_id, 
           u.user_name, 
           g.user_group_id,
           g.group_name
       FROM user u
       LEFT JOIN user_group g on JSON_CONTAINS(u.user_groups, CAST(g.user_group_id as JSON), '$')
    

    This appears to work, let me know if there's a better way.

提交回复
热议问题