I am using NodeJs mysql module and I want to check account existence before actually querying the password.
Here is the sql:
let sql = `IF EXISTS (SELECT name FROM users WHERE name='${data.name}') SELECT password FROM users WHERE name='${data.name}'`;
It works fine when no if statement and once IF EXISTS
part added in it, no matter what I adjust, always get the error like:
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage:
'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near...,
sqlState: '42000'
I will appreciate it if anyone can help me!