I have a table with these columns:
tel_number,date,time
There might be several records for a single tel_number. For each tel_number, I want to delete all except the record which has the most recent date from the table and in cases where there are multiple records for the most recent date, the one with the most recent time get to be selected and all the rest should be removed from the table.
for example from records like these:
1 2223333,14/01/28,08:30
2 2223333,14/01/27,08:30
3 2223333,14/01/28,16:30
4 2225555,14/01/27,10:34
5 2225555,13/12/29,10:34
all record except these two should be deleted:
3 2223333,14/01/28,16:30
4 2225555,14/01/27,10:34
edit:
I have tried this so far, but it doesn't delete records which has the same date but different times:
delete from table where (tel_number,date) not in
(select tel_number,max(date) from table group by tel_number);