在表中搜索不重复的记录语句该怎么写啊!谢了!
在表中搜索不重复的记录语句该怎么写啊!谢了!
问题点数:80、回复次数:14Top
1 楼AriesOracle(啥也不会...)回复于 2005-12-27 12:28:17 得分 5
select distinct 字段列表 ... from 表Top
2 楼cbz0660(珍)回复于 2005-12-27 12:30:50 得分 1
upTop
3 楼zlp321002(Life Is Good,Let's Shine)回复于 2005-12-27 12:35:25 得分 10
select * from 表
where 主键 in
(
select 主键 from 表
group by 主键
having count(*)=1
)
Top
4 楼windyghronger(多多)回复于 2005-12-27 12:35:39 得分 0
我的意思没有讲清楚!
是要把有重复的记录给找出来,没有重复的记录不要找出,Top
5 楼lichangzai(搞没搞定)回复于 2005-12-27 12:39:47 得分 2
楼上的对吗?
select distinct * from 表Top
6 楼zlp321002(Life Is Good,Let's Shine)回复于 2005-12-27 12:48:18 得分 10
select * from 表
where 主键 in
(
select 主键 from 表
group by 主键
having count(*)>1
)Top
7 楼funsuzhou(☆【处变不惊】☆)回复于 2005-12-27 12:53:36 得分 10
select * from 表 where exists(
select 列1,列2,列3,列4,列5...... from 表 group by 列1,列2,列3,列4,列5...... having count(*)>1
)
--列1,列2,列3,列4,列5......为所有的字段Top
8 楼funsuzhou(☆【处变不惊】☆)回复于 2005-12-27 12:54:19 得分 10
select * from 表 where exists(
select distinct * from 表
)Top
9 楼funsuzhou(☆【处变不惊】☆)回复于 2005-12-27 12:55:04 得分 10
不好意思,还是第一个对
select * from 表 where exists(
select 列1,列2,列3,列4,列5...... from 表 group by 列1,列2,列3,列4,列5...... having count(*)>1
)
--列1,列2,列3,列4,列5......为所有的字段
select * from 表 where exists(
select distinct * from 表
)
不对
Top
10 楼lichangzai(搞没搞定)回复于 2005-12-27 21:48:12 得分 1
上面好像还是不对!Top
11 楼lichangzai(搞没搞定)回复于 2005-12-27 22:25:37 得分 10
declare @t table(
a int,b int
)
insert @t
select 1,1 union all
select 1,2 union all
select 1,3 union all
select 1,1 union all
select 1,2 union all
select 2,4 union all
select 2,2
select a,b from @t
where exists(select a,b from @t group by a,b having count(*)>1 )
----------可是结果怎么还是这个呢
/*
1 1
1 2
1 3
1 1
1 2
2 4
2 2
*/Top
12 楼lichangzai(搞没搞定)回复于 2005-12-28 13:22:45 得分 1
upTop
13 楼flying02(和谐社会,诚信结贴)回复于 2005-12-28 14:44:09 得分 5
distinctTop
14 楼zhouhaihe()回复于 2005-12-28 16:25:24 得分 5
select a,b from @t group by a,b having count(*)>1Top




