I’m creating an api that fetches the latest logged in users.
if a filter param is true – filter to show online users only
if (Boolean.parse(isOnline)) {
filterConditions += ` AND u.lastLoginAt < NOW() - INTERVAL '15' MINUTE`;
}
but there appears to be a bug in this sql – where its returning all loggedin marked members , not just the ones that logged in only 15 mins ago?
–
is there an issue with the greater than formula here — is NOW() not getting the latest timestamp? is it because 15 is coded as a string?
SELECT u.*
FROM application.users_tbl u
WHERE u.role = 'user'
AND u.lastLoginAt < NOW() - INTERVAL '15' MINUTE
ORDER BY u.createdAt DESC;
6
I think you just should invert condition to >
AND u.lastLoginAt > NOW() - INTERVAL '15' MINUTE
9