3

I'm struggling to understand why my query isn't returning any results, please could you take a look and let me know what I'm doing wrong:

SELECT * FROM sys_online_users WHERE last_active BETWEEN NOW() AND DATE_SUB(NOW(), INTERVAL 10 SECOND) 

What I am trying to achieve is to show which users have been active within the last 10 seconds or any other time interval. However when I run the query I get no results, despite knowing that I have got updates in my table between the specified time range.

4 Answers 4

1

Yiu are going the wrong way with the between- first the ten seconds ago, and afterwards the now:

SELECT * FROM sys_online_users WHERE 
last_active BETWEEN DATE_SUB(NOW(),
INTERVAL 10 SECOND) 
AND NOW() 
1
  • I now noticed that for some reason the PHP that is writting the active time to my DB is an hour behind, that is also probably why I couldn't get and matches earlier, but now to add to the question, how do I fix that? Dec 11, 2015 at 11:21
0

Try this:

SELECT * FROM sys_online_users WHERE last_active BETWEEN DATE_SUB(NOW(), INTERVAL 10 SECOND) AND NOW()
0

Only columns placement error, try this:

SELECT * FROM sys_online_users WHERE last_active BETWEEN DATE_SUB(NOW(), INTERVAL 10 SECOND) AND NOW()
0

I have tried below query it is working perfect.In your query please take more gap with second then fire query you will get desired result

SELECT * FROM sys_online_users WHERE last_active BETWEEN DATE_SUB(NOW(), INTERVAL 50 SECOND) AND NOW();

In this query i have added 50 second so we can identify easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.