In my mysql database I have a table similar to this one:
Data |Val | Val2
2016-11-11 14:48:38 |10 | 20
2016-11-11 14:48:38 |30 | 40
2016-11-06 11:48:38 |50 | 60
2016-11-08 19:48:38 |70 | 80
2016-11-06 11:48:38 |90 |100
2016-11-16 10:13:37 |100 |110
2016-11-16 10:13:37 |120 |130
2016-11-16 10:16:43 |140 |150
2016-11-16 10:13:37 |140 |150
Sometimes in my database I can have duplicate dates (data) but different values for (val,val2), I wish to delete all the rows with duplicate data except the last one inserted on the database. How can I achieved that? For example, for the table above the result that I want is:
Data |Val |Val2
11/11/2016 14:48 |30 |40
08/11/2016 19:48 |70 |80
06/11/2016 11:48 |90 |100
16/11/2016 10:16 |140 |150
16/11/2016 10:13 |140 |150
I was using sqlite3 and I could achieve what I want by doing
delete from table where rowid not in (select max(rowid) from table group by data)
but I couldn't find the equivalent for mysql.