如何删除所有相同电子邮件地址的记录,但按日期保留最新的记录?MySQL中的日期格式为"0000-00-00“。我有以下问题:
delete from customer
where date not in (
select max(data)
from customer
group by email)看起来不管用。
你能展示一下如何在没有任何东西的基础上保留一条记录吗,因为我的记录没有id。
发布于 2018-03-02 09:23:17
使用获得每个客户的最新日期的子查询进行连接。
DELETE c1 FROM customer AS c1
JOIN (SELECT email, MAX(date) AS maxdate
FROM customer
GROUP BY email) AS c2
ON c1.email = c2.email AND c1.date != c2.maxdatehttps://stackoverflow.com/questions/49061311
复制相似问题