Sql 选择存在两个列表交点的查询
我有一个包含两列的表:Sql 选择存在两个列表交点的查询,sql,mariadb,Sql,Mariadb,我有一个包含两列的表: id(整数) list\u column(longtext)-包含json数组(例如[1,2,3]) 我想选择与输入列表相交的所有记录 让我解释一下: 我的输入是一个列表-[2,3] 伪代码: SELECT * FROM table WHERE intersection of [2, 3] and table.list_column is not empty list; 在SQL中可以这样做吗 我使用的是最新版本的 应该有效: MariaDB [(none)]>
id(整数)
list\u column(longtext)
-包含json数组(例如[1,2,3])[2,3]
伪代码:
SELECT *
FROM table
WHERE intersection of [2, 3] and table.list_column is not empty list;
在SQL中可以这样做吗
我使用的是最新版本的 应该有效:
MariaDB [(none)]> SET @json = '[1,2,3,4,5,6]';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SELECT JSON_CONTAINS(@json, '[1, 3, 5]');
+-----------------------------------+
| JSON_CONTAINS(@json, '[1, 3, 5]') |
+-----------------------------------+
| 1 |
+-----------------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> SELECT JSON_CONTAINS(@json, '[1, 2, 3]');
+-----------------------------------+
| JSON_CONTAINS(@json, '[1, 2, 3]') |
+-----------------------------------+
| 1 |
+-----------------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> SELECT JSON_CONTAINS(@json, '[7]');
+-----------------------------+
| JSON_CONTAINS(@json, '[7]') |
+-----------------------------+
| 0 |
+-----------------------------+
1 row in set (0.00 sec)
MariaDB [(none)]> SELECT JSON_CONTAINS(@json, '[5, 6, 7]');
+-----------------------------------+
| JSON_CONTAINS(@json, '[5, 6, 7]') |
+-----------------------------------+
| 0 |
+-----------------------------------+
1 row in set (0.00 sec)
非常感谢,这正是我想要的。