sql server 查询重复数据
id name age
1 张三 20
2 张三 21
3 张三 28
4 李四 22
5 王五 29
6 王五 23
id为主键
查询重复的记录
显示结果
1 张三 20
2 张三 21
3 张三 28
5 王五 29
6 王五 23
[解决办法]
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,'张三',20insert into tb select 2,'张三',21insert into tb select 3,'张三',28insert into tb select 4,'李四',22insert into tb select 5,'王五',29insert into tb select 6,'王五',23goselect * from tb where name in(select name from tb group by name having count(*)>1)/*id name age----------- ---------- -----------1 张三 202 张三 213 张三 285 王五 296 王五 23(5 行受影响)*/godrop table tb