S
S
Shakir Yakubov2020-07-02 19:15:39
MySQL
Shakir Yakubov, 2020-07-02 19:15:39

How to compare array and column from database?

Good afternoon, dear forum users. I need to make sure that my array is compared with a column from the db and check if there is such an element from the array in the db. For example:
I have array[1,2,3] and I need to check if my database has 1,2,3 in a column somewhere.
I am attaching my code (attempts):

async function checkQuery(object) {
  var numbers = [];
  for(let i = 0; i < urls[2].length; i++) {
    numbers[i] = urls[2][i];
  }
  console.log(numbers);
  sql = 'SELECT id FROM cases WHERE case_number in ("' + numbers.join('","') + '")';
  console.log(sql);
  await connection.execute(sql, function(err, results, fields) {
    console.log(err);
    console.log(results.length); // собственно данные
    console.log(fields); // мета-данные полей 
    for(let i = 0; i < results.length; i++) {
      if(results[i] === undefined) console.log('не найдено');
      else console.log('Дело найдено!');
    }
  });
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question