Am using MySQL 5, need to write a SQL statement(or stored procedure if needed) to delete all duplicate rows from this table for a given device except for the most recent row (youngest created_time)?
Here is the table:
desc user_detail;
Yields:
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------------------+-----------------------------+
| user_id | varchar(200) | NO | PRI | | |
| device | text | YES | | NULL | |
| created_time | timestamp | NO | | 0000-00-00 00:00:00 | |
| updated_time | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |