select * from table1 t
where exists(select 1
from table1
where Name=t.Name
and SheFenZheng=t.SheFenZheng
and id<>t.ID)
where exists(select 1
from table1
where Name=t.Name
and SheFenZheng=t.SheFenZheng
and id<>t.ID)
select * from 表 a
where exists (select 1 from 表 name=a.name and SheFenZheng=a.SheFenZheng and Id<a.id)
select * from table
where name not in
(
select name
from table
group by name
having count(name)>1)
如果你想几个字段不重复的话,都设为主键唠
where (select 1
from table1
where Name=t.Name
and SheFenZheng=t.SheFenZheng
and id<>t.ID) >0
(
id int,
name char(10),
shenfenzheng char(30)
)insert into @
select '1','张三','11'
union all
select '2','李四','12'
union all
select '3','王五','13'
union all
select '4','李四','10'
union all
select '5','王五','13'
union all
select '6','张三','11'select [name] from @
group by [name],shenfenzheng
having count(shenfenzheng) > 1
where exists(select 1
from table1
where Name=t.Name
and SheFenZheng=t.SheFenZheng
and id<>t.ID)
当NAME和SheFenZheng 都一样时的记录存在时就抽出来主键可以是一个,也可以是多个,但每一个组合起来都不同的
开始--程序--Micorosoft SQL Server---查询分析器--选SQL所在的服务器,输入用户(sa)和密码。 --就进入
在中上方选择你要操作的数据库,然后在下面空白的地方输入或帖上下面这句:select * from table1 t
where exists(select 1
from table1
where Name=t.Name
and SheFenZheng=t.SheFenZheng
and id<>t.ID)之后再点菜单上面 查询--执行!
where exists(select 1
from table1
where Name=t.Name
and SheFenZheng=t.SheFenZheng
and id<>t.ID)能给说明一下么。特别是 tabl1 和 t 是什么关系?
table1 是不是就是我的原始表? t 又是什么?谢谢
--------- ????
where exists(select 1
--- ?????
from table1
where Name=t.Name
and SheFenZheng=t.SheFenZheng
and id<>t.ID)能给说明一下么。特别是 tabl1 和 t 是什么关系?
table1 是不是就是我的原始表? t 又是什么?
where exists(select 1 ---- 是什么意思谢谢