Remove duplicate records with timestamps I have a table in my DB where I keep track of user data. So I have rows like that: 

(row_id,user_id, stat1,stat2,..., statN, timestamp)


Now I want to remove all duplicate records, where user_id and stat columns are the same, but only between other rows with different data. So if I have 

(row_id, user_id, stat1, stat2, stat3, timestamp)
(1,1,1,0,1,1000)
(2,1,1,1,1,2000)
(3,1,1,1,1,3000)
(4,1,1,0,1,4000)


It should became 

(1,1,1,0,1,1000)
(2,1,1,1,1,2000)
(4,1,1,0,1,4000)


And not 

(1,1,1,0,1,1000)
(2,1,1,1,1,2000)


So I want to save record progression but remove meaningless duplicates.
So doing a join on the elements that constitute a duplicate and the last where criteria shows which to delete.

delete t1
from table t1, table t2
where t1.user_id = t2.user_id and t1.stat1=t2.stat1
     and t1.stat2=t2.stat2  and t1.stat3=t2.stat3
and t1.row_id+1=t2.row_id