日期:2014-05-18 浏览次数:20453 次
select * from tb a where exists(select 1 from tb where name=a.name and id<>a.id)
------解决方案--------------------
create table tb(id int,name varchar(10),age int) insert into tb select 1,'张三',20 insert into tb select 2,'张三',21 insert into tb select 3,'张三',28 insert into tb select 4,'李四',22 insert into tb select 5,'王五',29 insert into tb select 6,'王五',23 go select * from tb where name in(select name from tb group by name having count(*)>1) /* id name age ----------- ---------- ----------- 1 张三 20 2 张三 21 3 张三 28 5 王五 29 6 王五 23 (5 行受影响) */ go drop table tb