例如有如下表结构和值
table
fid name sex
1 a 男
2 b 男
3 c 女
4 d 女
5 a 男
6 b 男
select distinct name from table打开重复记录的单个字段
select * from table where fid in(Select min(fid) FROM table group by name)打开重复记录的所有字段值
select * from table where
table
fid name sex
1 a 男
2 b 男
3 c 女
4 d 女
5 a 男
6 b 男
select distinct name from table打开重复记录的单个字段
select * from table where fid in(Select min(fid) FROM table group by name)打开重复记录的所有字段值
select * from table where
select * into tb from (
select 1 fid,'a' [name],'男' sex
union all
select 2 , 'b', '男'
union all
select 3, 'c', '女'
union all
select 4 ,'d', '女'
union all
select 5 , 'a','男'
union all
select 6, 'b', '男' )aselect tb.* from tb inner join (
select [name],sex from tb group by [name],sex having count(1)=1
) a
on tb.[name]=a.[name] and tb.sex=a.sex-----------
/*
fid name sex
3 c 女
4 d 女
*/
select [name],sex from tb group by [name],sex having count(1)>[code=SQL]1
) a
on tb.[name]=a.[name] and tb.sex=a.sex[/code]
select [name],sex from tb group by [name],sex having count(1)>1
) a
on tb.[name]=a.[name] and tb.sex=a.sex[/code]