How can I group lines based on field value? A RANK() case, maybe?

For a bad implementation, we have a situation like this:

+-----------+-------- +-----------+-----------+-----------+---------+------------------------+---------------------+---------------------+-----------+----------+---------+--------
| id        | event_n | reader_id | entity_id | school_id | root_id | event_value            | created_at          | updated_at          | event_flo | event_int| user_id | teacher
+-----------+-------- +-----------+-----------+-----------+---------+------------------------+---------------------+---------------------+-----------+----------+---------+--------
| 345678270 | search  | 2511678   | 193765    | <null>    | 65478   | Du mmy                 | 2021-04-05 19:24:11 | 2021-04-05 19:24:11 | <null>    | <null>   | 2634876 | <null> 
| 345678286 | search  | 2511678   | 193765    | <null>    | 65478   | Du mmyntex             | 2021-04-05 19:24:13 | 2021-04-05 19:24:13 | <null>    | <null>   | 2634876 | <null> 
| 345678366 | search  | 2511678   | 193765    | <null>    | 65478   | Du mmyntexas           | 2021-04-05 19:24:17 | 2021-04-05 19:24:17 | <null>    | <null>   | 2634876 | <null> 
| 345678370 | search  | 2511678   | 193765    | <null>    | 65478   | Du mmyntexas de ma     | 2021-04-05 19:24:17 | 2021-04-05 19:24:17 | <null>    | <null>   | 2634876 | <null> 
| 345678388 | search  | 2511678   | 193765    | <null>    | 65478   | Du mmyntexas de make   | 2021-04-05 19:24:18 | 2021-04-05 19:24:18 | <null>    | <null>   | 2634876 | <null> 
| 345678823 | search  | 2587432   | 61567     | <null>    | 65478   | du mmyntexas do clock  | 2021-04-05 19:24:52 | 2021-04-05 19:24:52 | <null>    | <null>   | 2713377 | <null> 
| 345678315 | search  | 2511678   | 193765    | <null>    | 65478   | Du mmyntexasd          | 2021-04-05 19:24:14 | 2021-04-05 19:24:14 | <null>    | <null>   | 2634876 | <null> 

Only the bigger length event_value column was supposed to be recorded. We already fixed this crap. But, anyone can see a way to group by those registers, so I could delete them, leaving only the biggest length?

I though about using, maybe, RANK() function, but couldn’t find a way to group those values.

Answer

Something like

DELETE t1
FROM tablename t1
JOIN tablename t2 
    -- adjust joining columns list
    USING (event_n, reader_id, entity_id, user_id)
WHERE LOCATE(t1.event_value, t2.event_value) = 1
  AND t1.created_at < t2.created_at
  -- adjust time gap length
  AND t1.created_at + INTERVAL 1 MINUTE > t2.created_at 

or the same using WHERE EXISTS.