I need to retrieve a random ID from the table nodes
within the last 15 seconds.
I attempted the following code, but it produced a lengthy output:
const mysql = require('mysql');
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'password',
database: 'DAGtest3'
});
connection.connect((err) => {
if (err) throw err;
console.log('Database Connected!');
});
var b = connection.query("SELECT t.`id` FROM `nodes` AS t
INNER JOIN (SELECT ROUND( RAND() * (SELECT MAX(id) FROM `nodes` )) AS id ) AS x
WHERE t.id >= x.id AND created_at < DATE_SUB(NOW(), INTERVAL 15 SECOND) LIMIT 1");
console.log(b);
output
Query // Output details removed for brevity
Any suggestions on how to resolve this issue?