deleting loop through mysql db
I'm trying to write a query to delete old(1 week or more) unactivated dB entries
there is a field called "activated" which is boolean (0 for unactivated)
and a field called "date_reg" which is a unix timestamp.
i want to check if the difference of time between now and the date of registration is more than 604800 seconds (1 week), do i need to loop through each field and make a comparison (with PHP) or is there any faster way, like an in-query operation that i can do?
also is there a way to limit it, in case that in the future there are too many users, so it doesn't slow the PHP script too much..something like LIMIT?
thanks for reading, hope you can help
DELETE FROM table_name WHERE activated = 0 AND
(CAST(UNIX_TIMESTAMP() AS SIGNED) - CAST(date_reg AS SIGNED)) > 604800;
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)