SQL语句去掉重复记录,获取重复记录
--查询一个表中有效去掉重复的记录,UserID为自增长主键,RoleID为重复字段
SELECT MIN(UserID) AS UserID, RoleID FROM tmpTable GROUP BY RoleID
SELECT RoleID FROM tmpTable GROUP BY RoleID HAVING (COUNT(*) > 1)
SELECT DISTINCT * FROM tmpTable
SELECT MIN(UserID) AS UserID, RoleID FROM tmpTable GROUP BY RoleID
SELECT RoleID FROM tmpTable GROUP BY RoleID HAVING (COUNT(*) > 1)
SELECT DISTINCT * FROM tmpTable