soileh
soileh

Reputation: 5

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:

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.

Upvotes: 0

Views: 230

Answers (1)

Strawberry
Strawberry

Reputation: 33945

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.

Upvotes: 1

Related Questions