How do I remove duplicate entries in a given timeframe? My table looks like this:

+-----------+
|     id    | &lt;- primary key
|    time   | &lt;- DateTime
|    row2   | &lt;- varchar
|    row3   |
|    ...    |
+-----------+


I want to remove all entries, except one, which are within a timeframe of one full hour and have the same value of row2 (distinct row2). Is it possible to do this without a stored procedure and/or non-sql code?
The usual solution for this problem is first looking for the rows you want to keep, and then delete all others.  The first part can be accomplished with an aggregate and grouping:

SELECT min(id)
FROM my_table
GROUP BY row2, DATE_FORMAT(`time`, '%Y-%m-%d %H')


Then you can write your DELETE:

DELETE FROM my_table
WHERE id NOT IN (
    SELECT min(id)
    FROM my_table
    GROUP BY row2, DATE_FORMAT(`time`, '%Y-%m-%d %H')
);


There are variations to this theme: you can use a NOT EXISTS construct instead of NOT IN (with appropriate changes), or a join using the USING keyword.