Reputation: 97
I keep getting the following error code
Error: ER_BAD_FIELD_ERROR: Unknown column 'kappa' in 'where clause'
when executing this script in nodejs
connection.query('SELECT balance FROM members WHERE username = kappa', function(err, data) {
if (!err)
console.log(data);
else
console.log(err);
});
im unsure why this is happening, is my syntax wrong or something?
Upvotes: 1
Views: 13190
Reputation: 409
You can always try the same codes in MySQL Workbench, it will tell the same error.
SELECT balance FROM members WHERE username = kappa
// Error Code: 1054. Unknown column 'kappa' in 'where clause'
SELECT balance FROM members WHERE username = "kappa"
// No error for this codes.
Upvotes: 0
Reputation: 1
Try this:
SELECT balance FROM members WHERE username = "'+kappa+'"
Upvotes: -2
Reputation: 26298
For comparing with strings use single quotes like:
"SELECT balance FROM members WHERE username = 'kappa'"
try with this query.
Upvotes: 7