My question is as follows:
select exists (select * from visit where time like "April 17%") as 'res';
Upon running this query, it outputs the following:
+--------------+
| res |
+--------------+
| 1 |
+--------------+
I am looking to only retrieve the value 1. This specific query can be helpful for individuals utilizing mySQL and node.js:
app.post('/qr', function(req, res) {
console.log("Check QR code.");
let now = moment().format('MMMM Do YYYY, h:mm:ss a');
let subnow = now.substr(0, 8);
let subnowwild = subnow + "%";
connection.query("select exists (select * from visit where time like ?)", subnowwild, function(err, result) {
if (err) throw err;
console.log(result);
if(result = 0) {
res.redirect(307, '/savedata');
}
else {
res.redirect(307, '/updatedata');
}
});
});
To elaborate on the code snippet, it redirects to different routes based on the query result. It's helpful when troubleshooting similar issues or confusion in the process.
In essence, I need the output to be just 0 for data saving purposes, rather than the value within the table. This functionality could come in handy if you have varied actions depending on the query response, but my requirement is solely for the numerical return outside of the table.