我需要从table1
字段的table2.properties
表中选择所有项目,该字段是JSON数据。
示例数据:
Table1:
--------
id
--------
1
2
3
--------
Table2:
-------------------------------------
id | properties
-------------------------------------
11 | {"ids": ["1"]}
12 | {"ids": ["1","3"]}
13 | {"ids": ["2","3"]}
-------------------------------------
我可以将id作为数组获取 通过该查询
> select JSON_EXTRACT(properties, '$.ids') from `table2` where id=11;
+-------------------------------------+
| JSON_EXTRACT(properties, '$.ids') |
+-------------------------------------+
| ["1"] |
+-------------------------------------+
但是当我尝试获取table1
时,它不起作用
> select * from `table1` where id in (
select JSON_EXTRACT(properties, '$.ids') from `table2` where id=11
);
[empty result]