mysql - 如何在IN

时间:2017-08-20 17:37:57

标签: mysql arrays json

我有一个名为JSON的{​​{1}}列的表格。我使用它存储和数组,现在我想在related内使用这个数组。我怎么能这样做?

e.g。 IN

SELECT * FROM products WHERE id IN (select related FROM products WHERE id = 1);返回SELECT related FROM products

1 个答案:

答案 0 :(得分:0)

您可以使用功能

更新2 :(已测试):

SELECT
`id`,
`related`
 FROM
`products`
 WHERE
    JSON_SEARCH((SELECT `related` FROM `products` WHERE `id` = 4) ,'one', `id`)
             IS NOT NULL;

见此(已更新):https://www.db-fiddle.com/f/5ESH1X9qjB46GAzG6DkdfJ/1

另见:

https://benjaminlistwon.com/blog/working-with-json-data-in-mysql-part-1-of-3/