
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 0.69 KB | hits: 16 | expires: Never
removing duplicates from mysql table but allowing up to 10
SELECT
ip,
date,
count(ip) as count
FROM
table
WHERE
date
BETWEEN
'2012-02-03 00-00-00'
AND
'2012-02-03 23:59:59'
group by
ip
having
count > 10
delete t2
from table t2
join (
SELECT ip, date, (
select count(*) from
table t1
where t1.ip = t.ip and t1.date <= t.date and
t1.date BETWEEN '2012-02-03 00-00-00' AND '2012-02-03 23:59:59'
) as row
FROM table t
WHERE date BETWEEN '2012-02-03 00-00-00' AND '2012-02-03 23:59:59'
) t3 on t2.date = t3.date and t2.ip = t3.ip and t3.row > 10