I have a table which contains information relating to user sessions, product id's and quantities for a shopping cart system I'm developing.
Now each time a visitor adds a product to their basket, the sessionID, productID and quantity are saved to this table. If they set the product quantity to 0 it deletes the entry in the table.
The problem I have is that when users close their browser without emptying their cart first, these records remain in the database forever more! This I don't want.
It then struck me that each time an item is added to that table, the same script could check for "expired" entires and delete them based upon a timestamp type field which I could add to the table.
So, my question is this: Is there a simple sql query which would filter all items older than a prefixed amount based upon the current timestamp and what data field type should I add to my table to handle this?
Alternatively, is there a better way to achieve this?