1、表中存的数据如下图,a,b是重复数据
2、 我们要查询出的数据如下图
3、首先查出重复数据的name,再查出重复数据的id,最后子查询出不重复的数据
(1)SELECT name from test GROUP BY name HAVING count(name) > 1
(2)SELECT id from test WHERE name in (SELECT name from test GROUP BY name HAVING count(name) > 1)
(3)SELECT * from test WHERE id not in
(SELECT id from test WHERE name in (SELECT name from test GROUP BY name HAVING count(name) > 1))