I'm trying to make a very simple statistics script.
I have a table data ( ip, date, page )
.
I want to insert ip and current page to this table only if there isn't the same ip and page since the last 15 minutes.
Here is the last SQL I tried :
INSERT INTO data ( `ip` , `date` , `page` )
SELECT ( :ip , NULL , :page )
WHERE NOT EXISTS (
SELECT * FROM data
WHERE `ip` = :ip AND `page` = :page AND date BETWEEN timestamp(DATE_SUB(NOW(), INTERVAL 15 MINUTE)) AND timestamp(NOW())
)
The SELECT inside "not exists" works when used alone. Any help appreciated !