我有一个名为JSON
的{{1}}列的表格。我使用它存储和数组,现在我想在related
内使用这个数组。我怎么能这样做?
e.g。 IN
和SELECT * FROM products WHERE id IN (select related FROM products WHERE id = 1);
返回SELECT related FROM products
答案 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/