i have the folowwing tables on mysql 5.7 server
produit__parure
id_parure (int) | ids_produits_parure (json) |
---|---|
21 | ["34809", "34823", "34813"] |
22 | ["35703", "35854", "35877"] |
and produit
:
id_product (int) | ... other columns |
---|---|
34809 | ... |
34810 | ... |
i try to join both on id.prod = value on ids_produits_parure with this query:
SELECT p.id_prod, pp.* FROM produit p left JOIN produit__parure pp on
JSON_CONTAINS(pp.ids_produits_parure->'$[*]', CAST(p.id_prod as JSON))
where id_prod=34809
but it return NULL on produit__parure fileds:
id_prod | id_parure | ids_produits_parure |
---|---|---|
34809 | NULL | NULL |
what am i doing wrong? what i want as a result is:
id_prod | id_parure | ids_produits_parure |
---|---|---|
34809 | 21 | ["34809", "34823", "34813"] |
i tried Dan Chase answer but it produce wrong results (i have lines with ids_produits_parure not equal to id_prod )
id_prod | id_parure | ids_produits_parure |
---|---|---|
34809 | 21 | ["34809", "34823", "34813"] |
34809 | 22 | ["35703", "35854", "35877"] |