Why this MySQL query returns 0 results

I try to get all the records in the last 5 minutes, but returns nothing.

SELECT * FROM (`user_actions`) WHERE `IP` = '127.0.0.1' AND `type` = 'Failed Login' AND date =DATE_SUB(NOW(), INTERVAL 5 MINUTE) 
+3
source share
2 answers

It does not return anything, because there are no results for what you ask .... the date is exactly 5 minutes ago.

You should not use an operator =for yours DATE; you must use inequalities.

That is, you want the date to be more than 5 minutes ago

+2
source

It should be date >not date =, which will correspond only to lines exactly equal to the time 5 minutes ago.

, 12:30 , , 5 , , 12:25 . , 12:25 PM, 12:26, ​​12:27 ..

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

Source: https://habr.com/ru/post/1792049/


All Articles