开发者

Why does this MySQL query return 0 results

I am trying to get all records in the past 5 minutes but it is returning nothing..

SELECT * FROM (`user_actions`) WHERE `IP` = '127.0.0.1开发者_如何学编程' AND `type` = 'Failed Login' AND date =DATE_SUB(NOW(), INTERVAL 5 MINUTE) 


It's returning nothing because there no results for what you're asking for.... a date of exactly 5 minutes ago.

You should not use the = operator for your DATE, you should be using inequalities.

That is, you want the date greater than 5-minutes-ago


It should be date > not date =, which would only match rows exactly equal to the time 5 minutes ago.

As an example, if it is currently 12:30PM, to find the rows that are within the last 5 minutes, you want all those with a time greater than 12:25PM. Querying only for rows with a time equal to 12:25PM won't give you those recorded at 12:26PM, 12:27PM, etc.

SELECT * FROM user_actions WHERE IP = '127.0.0.1' AND type = 'Failed Login' AND date > DATE_SUB(NOW(), INTERVAL 5 MINUTE) 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜