id_specific_price id_product
-------------------------------
1 2
2 2
3 2
4 3
5 3
6 3
7 3
需要删除重复项,预期结果:
id_specific_price id_product
-------------------------------
3 2
7 3
SELECT *
FROM ps_specific_price
WHERE id_specific_price NOT IN
(SELECT MAX(id_specific_price)
FROM ps_specific_price
GROUP BY id_product)
有效,但
DELETE FROM ps_specific_price
WHERE id_specific_price NOT IN
(SELECT MAX(id_specific_price)
FROM ps_specific_price
GROUP BY id_product)
才不是。有很多例子可以解决这个问题,但由于某种原因我无法适应它。我相信它是 GROUP BY。例如:
DELETE FROM ps_specific_price
WHERE id_specific_price NOT IN
(SELECT MAX(p.id_specific_price)
FROM (SELECT * FROM ps_specific_price ) as p)
GROUP BY id_product
我在这里哪里做错了?