Basically this query should select all the fields inserted in the last 30 minutes, but it doesnt, it selects absolutely every row making my script output wrong data
SELECT count(*) FROM mytable
WHERE `time` >= DATE_SUB(UTC_TIMESTAMP, INTERVAL 30 minute)
My time field stores the time in this kind of format 2011-06-08 22:32:03
The query works, but it selects every row, not the ones inserted in the last 30 minutes.
Add parentheses to your query –
UTC_TIMESTAMP()or useNOW()– quite simpler for me.