简体   繁体   English

MYSQL查询以查找数组的元素

[英]MYSQL Query to find an element of an Array

I have a column where data is saved in the following syntax: 我有一列使用以下语法保存数据的列:

Value1;Value2;Value3

I have an array and I would like to check if any of the elements contain a value in the table. 我有一个数组,我想检查表中是否有任何元素包含值。 I read a little bit and found that the SQL Query:"WHERE...IN.. should do this but I havent done it successfully right now. Here is my command: 我读了一点,发现SQL查询:“ WHERE ... IN ..应该这样做,但是我现在还没有成功完成。这是我的命令:

db.query(

'SELECT * FROM blocklist WHERE BanContent IN ?', [inputarray.join(",")],
function (err, results) {
    try {

        console.log(results)

    } catch (err) {
        console.log(err);
    }

});

I allways get undefined as the result. 我总是得到不确定的结果。

Consider the following: 考虑以下:

SELECT FIND_IN_SET('v2',REPLACE('v1;v2;v3',';',','))x;
+---+
| x |
+---+
| 2 |
+---+

And now see about normalisation and why it's a bad idea to store delimited data in an RDBMS. 现在,您将了解规范化以及将定界数据存储在RDBMS中为什么不是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM