For example, I have this sample data:
DATE VALUE ID
2010-09-28 1 20000
2010-09-28 1 50000 X
2010-09-28 3 20001
2010-09-28 3 50001 X
2010-10-02 6 50002
2010-10-02 6 50003
My problem is that I have duplicated data, and I can only differentiate them by the auto-incremented ID: the duplicate has quite a good margin of difference; I’d like to delete the latest entries, considering the date and value are equal compared to their corresponding previous entry (marked with X). It is no problem though if rows are equal, if they don’t have a previous ID (as in the last 2 rows).
Any ideas?
In your table the ones with the X do not have the same Value… I ´ll suppose that this is a mistake.
Anyway if you want to delete duplicates when the difference between the IDs is (for example 1) you could do this.
EDIT: I think I get what you want now. So you don’t consider as duplicates records that have succesive Ids (which is what I thought in the beggining) but you consider duplicates records who have a large difference. So lets say the maximum difference between IDs so you won’t consider them duplicates = X
In your example if you put 1 or larger in place of X it will do the job that you want.
SQL FIDDLE EXAMPLE OF THE SELECTION USED TO DELETE
You will see above that with the selection i’ve given you, you get the Ids you want to delete.