mysql query json_MySql Query with Json

Based on the information you provided I assume you need M:N relationship to depict your relationship between the JSON data and the original table you outlined in your post.

Your original Table (updated)

+------------+----------------+------------+

| shop_id | id_lang | id_image |

+------------+----------------+------------+

| 1 | 1 | 2 |

| 1 | 1 | 3 |

| 1 | 1 | 4 |

+------------+----------------+------------+

New Table

+-------------+----------------+

| group_id | desc/name |

+-------------+----------------+

| 1 | Visit |

| 2 | Guest |

| 3 | Customer |

| 4 | Other |

| 5 | Test |

+-------------+----------------+

Relationship/Join Table:

+-------------+-------------------+

| FK group_id | FK Original Table |

+-------------+-------------------+

| 1 | A |

| 1 | B |

| 2 | C |

| 4 | D |

| 5 | E |

+-------------+-------------------+

Obviously you have in this case to either store the JSON as an duplicate or what would be even better and this is also what I would recommend => reconstruct it from the data you fetch from the DB.

The above table example is just as a hint how this could be realised on DB level. If you don't need a reconstruction of the data I wouldn't even bother at all on the original JSON. I don't know what the primary key of you original table is so I added a generic key for the join table.

Updated: removed 1:N because M:N is needed.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值