Skip to content
Advertisement

Using left join to query and match JSON field in MySQL

Table A,field : pay_type_fk,type:json, Examples Data: [1,2,4] Table B,field : id type : bigint Examples Data: primary key

SQL I use:

Only pay can be found_ For the first record in the type table, I think we can query all of them with group_ CONCAT

Advertisement

Answer

If I follow you correctly, you can join on JSON_CONTAINS():

That said, a better option would be to fix your design. Instead of using a JSON array to store multiple dependent keys, you should have a separate bridge table to represent this many-to-many relationship, with each value in a separate row.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement