Question: I have daily price of some items stored in a table, for each product ID along with date. I want to delete newer price record if it's same as previous. Or moving from older to newer, if the next record for that product ID has same price, I want to delete it. My primary key includes all three fields so not much of use here.

This is my table structure.

```
productID  Price    Rdate                  #
1           210     2015-05-01             1
2           55      2015-05-01             2
3           9       2015-05-01             3             
1           211     2015-05-02             4
2           53      2015-05-02             5
1           211     2015-05-04             6
1           210     2015-05-05             7
1           211     2015-05-08             8

```

productID - INT (foreign key)

Price - SMALLINT (UNSIGNED)

Rdate - DATE

EDIT: In this example, I want to delete #6 (but not #8), since the price is same as previous one date. I want to delete #6 because price record same on previous date too so it doesn't make sense to keep two entries. I just want to keep record of "price change" , not price for each day.

Is it possible to delete it using a single query? Even if I have to loop the query for each ID, it'll be fine.

Answer: 
Assume your table name is `Item`

```
DELETE 
FROM Item i 
WHERE EXISTS(
    SELECT * 
    FROM Item 
    WHERE 
        productID = i.productID 
        AND PRICE = i.PRICE 
        AND Rdate < i.Rdate
)

```
Try this;)

```
delete a
from yourtable a
inner join yourtable b on a.productID = b.productID and a.Price = b.Price and a.Rdate > b.Rdate

```