mysql查询根据一个字段或者两个字段内容重复的记录并将其全部删除

根据一个字段内容重复的记录并将其全部删除

DELETE FROM unionid2userid WHERE unionid IN (SELECT w.unionid FROM (SELECT unionid,COUNT(*) AS COUNT FROM unionid2userid GROUP BY unionid HAVING COUNT>1) w)

根据两个字段重复的记录查询出来

SELECT * FROM (SELECT *, CONCAT(aUserID,bUserID) AS nameAndCode FROM enntouchlist) t WHERE t.nameAndCode IN 
(
    SELECT nameAndCode FROM (SELECT CONCAT(aUserID,bUserID) AS nameAndCode FROM enntouchlist) tt GROUP BY nameAndCode HAVING COUNT(nameAndCode) > 1
)

你可能感兴趣的:(mysql查询根据一个字段或者两个字段内容重复的记录并将其全部删除)