I have a SQL query in node.js for my proposing system The feature should insert data when there isn't included same data in current table.
var sql= `
SELECT IF(
EXISTS(SELECT student_id FROM propose_${propose} WHERE student_id = '${user}'),
(INSERT INTO propose_${propose} (student_id) VALUES ('${user}')),
NULL
)
`
client.query(sql,(err,data)=>{
if(err)throw err;
console.log(data)
})
as the code,query should be sent as:
SELECT IF(
EXISTS(SELECT student_id FROM propose_a WHERE student_id = 'account'),
(INSERT INTO propose_a (student_id) VALUES ('account')),
NULL
)
but it returns SQL syntex error
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INTO propose_a (student_id) VALUES ('account')),\n" +
' NULL\n' +
" )' at line 3",
sqlState: '42000',
The problem might arose around "INSERT INTO" in the line 3 of sql query