I need to exclude duplicate records in the `bidding_price` column with the following conditions:

Table: `bid_account`

Columns to check:

> 
> `id` = PRIMARY KEY  
>  `auction_id` = ID of each product  
> 
> `bidding_price` = inserted value (this must be checked for duplicity for each product)  
> 
> `bid_flag` = must always equal the value of: **'d'**  
>  `bidding_type` = must always equal the value of:: **'s'**
> 
> 
> 

It will always exist equal records in the `bidding_price` column, which it can not have is equal records with the same product ID (`auction_id`).

Example of how it should not have:

> 
> **auction\_id** | **bidding\_price**  
> 
> *------10------------0.02  
> 
>  ------10------------0.02  
> 
>  ------11------------0.02  
> 
>  ------11------------0.02*
> 
> 
> 

The correct would be:

> 
> **auction\_id** | **bidding\_price**  
> 
> *------10------------0.02  
> 
>  ------11------------0.02*
> 
> 
> 

I tried with the following command:

```
DELETE ba
    FROM bid_account ba JOIN
         (SELECT ba2.auction_id, ba2.bidding_price, MAX(ba2.id) as max_id
          FROM bid_account ba2
          WHERE ba2.bid_flag = 'd' AND ba2.bidding_type = 's'
          GROUP BY ba2.auction_id, ba2.bidding_price
         ) ba2
         ON ba2.auction_id = ba.auction_id AND
            ba2.bidding_price = ba.bidding_price AND
            ba2.max_id < ba.id
WHERE ba.bid_flag = 'd' AND ba.bidding_type = 's' AND ba.auction_id = ba2.auction_id

```

The problem is that it deleted multiple records that it should not delete, did not do the validations correctly. How can I do it?