你的KSON_包含有点。
Json在大多数情况下都很难处理,因此您应该考虑切换到规范化设计
CREATE TABLE produit__parure
(`id_parure` int, `ids_produits_parure` json)
;
INSERT INTO produit__parure
(`id_parure`, `ids_produits_parure`)
VALUES
('21', '["34809", "34823", "34813"]'),
('22', '["35703", "35854", "35877"]')
;
CREATE TABLE produit
(`id_product` int, `other columns` varchar(3))
;
INSERT INTO produit
(`id_product`, `other columns`)
VALUES
(34809, '...'),
(34810, '...')
;
SELECT JSON_CONTAINS(`ids_produits_parure`, CONCAT('"','34809' ,'"'), '$') FROM produit__parure
| JSON_CONTAINS(`ids_produits_parure`, CONCAT('"','34809' ,'"'), '$') |
| ------------------------------------------------------------------: |
| 1 |
| 0 |
SELECT p.id_product, pp.* FROM produit p left JOIN produit__parure pp on
JSON_CONTAINS(pp.ids_produits_parure, CONCAT('"',p.id_product,'"'),'$')
where id_product=34809
id_product | id_parure | ids_produits_parure
---------: | --------: | :-----------------------------------------------------
34809 | 21 | 5b223334383039222c20223334383233222c20223334383133225d
db<>不停摆弄
here