-1

I have the code

  const defer = Q.defer();
    var sql = "SELECT * FROM test WHERE type != ? AND externalUserId != ?";
    db.query(sql, [options.type, options.externalUserId], (err, result) => {
        if (err) {
            console.dir(err);
            defer.reject(err);
        } else {
            defer.resolve(result);
        }
    });
    return defer.promise;

I'm trying to select all rows that don't have a certain type. The code above returns the wrong results. Does anyone know why?

Chris Hansen
  • 7,813
  • 15
  • 81
  • 165

1 Answers1

0

You should enclose all strings inside single quotes. Try this: "SELECT * FROM test WHERE type != '?' AND externalUserId != '?'"

Also, I would recommend you use <> instead of !=. Here is why.

Muhammed Jaseem
  • 782
  • 6
  • 18