0

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.

10
  • IN requires the values it should check for to be in parenthesis. Commented Sep 14, 2017 at 13:31
  • Can i give you example of PHP PDO Query? but i think you are using Console? im not familiar with console. Commented Sep 14, 2017 at 13:32
  • "select * from blocklist where BanContent IN ", [inputarray.join(",")], function (err, results) Commented Sep 14, 2017 at 13:35
  • 1
    Where did you read that IN could do this? Commented Sep 14, 2017 at 13:38
  • Why not, maybe it helps. @waka is there a sql query which work the way I need it or do i need to for loop every array element. Would not be the worst case since the array I want to check is not that big. Commented Sep 14, 2017 at 13:38

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.