I'm running a reverse auction website and I need to delete the duplicate bids and keep only the highest amount . lastPriceBid_rounded is the "amount". The duplicate is defined by the userId.
+----------------------+--------------+------+-----+-------------------+-------------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+-------------------+-------------------+
| lastPriceBid | varchar(125) | YES | | NULL | |
| dateBidded | varchar(125) | YES | | NULL | |
| owner | varchar(65) | YES | | NULL | |
| status | int(11) | YES | | 0 | |
| userId | varchar(125) | YES | | NULL | |
| siteId | int(11) | YES | | NULL | |
| lastPriceBid_rounded | int(11) | YES | | NULL | |
| from_nickname | varchar(125) | YES | | NULL | |
| id | int(11) | NO | PRI | NULL | auto_increment |
| time_updated | timestamp | NO | | CURRENT_TIMESTAMP | on update |
| CURRENT_TIMESTAMP |
+----------------------+--------------+------+-----+-------------------+-------------------+
So far I've tried
DELETE n1
FROM offers n1, offers n2
WHERE n1.lastPriceBid_rounded < n2.lastPriceBid_rounded
AND n1.userId = n2.userId;
but it doesn't seem to work well. I still have some duplicates (I see that when I use SELECT DISTINCT).