如何查找不重复的记录
比如一个表(T)有以下字段及内容:
ID NAME
1 A
2 B
3 C
3 CCCCC
4 D
5 E
5 EEE
通过一个条查询语句后我想要得到的结果为
ID NAME
1 A
2 B
3 C
4 D
5 E
请问只用一条SQL语句怎么写呀?
[解决办法]
create table test(ID int,NAME varchar(10))
insert test select 1, 'A '
union all select 2, 'B '
union all select 3, 'C '
union all select 3, 'CCCCC '
union all select 4, 'D '
union all select 5, 'E '
union all select 5, 'EEE '
select * from test a where NAME=
(
select top 1 NAME from test where ID=a.ID
)
[解决办法]
select ID,min(Name) as Name from 表 group by ID
[解决办法]
select id,min(NAME) from T group by id ?
[解决办法]
select ID,min(Name) as Name from T group by ID
[解决办法]
--如果仅有这两个字段,直接分组即可:
select
id,
min(name) as name
from 表
group by id
order by id