我有一张桌子:
id product id merchant id price upc
1 124 2 2000000 1234XDE
2 124 2 200000 1234XDE
3 124 2 200000 1234XDE
4 124 2 200000 1234XDE
5 124 2 200000 ASDER36
6 134 1 300 ASERT56
7 134 2 300 ASERT56
我想删除表中的所有多个条目。
Delete from
table where id not in (Select min(id) from table group by(merchant id))
但没有成功。我希望结果表为:
id product id merchant id price upc
1 124 2 2000000 1234XDE
5 124 2 2000000 ASDER36
6 134 1 300 ASERT56
7 134 2 300 ASERT56
有人可以帮我写一个查询。
答案 0 :(得分:1)
这应该这样做:
delete from flash
where id not in (select min(id)
from flash
group by product_id, merchant_id, upc);
SQLFiddle示例:http://sqlfiddle.com/#!15/9edef/1