![](http://static.javashuo.com/static/loading.gif)
declare @t table(id
int identity(
1,
1), v varchar(
10))
![](http://static.javashuo.com/static/loading.gif)
insert @t select
'
a
'
![](http://static.javashuo.com/static/loading.gif)
union all select
'
b
'
![](http://static.javashuo.com/static/loading.gif)
union all select
'
c
'
![](http://static.javashuo.com/static/loading.gif)
union all select
'
d
'
![](http://static.javashuo.com/static/loading.gif)
union all select
'
e
'
![](http://static.javashuo.com/static/loading.gif)
union all select
'
b
'
![](http://static.javashuo.com/static/loading.gif)
union all select
'
c
'
![](http://static.javashuo.com/static/loading.gif)
--a語句in的sql寫法
![](http://static.javashuo.com/static/loading.gif)
select * from @t
where v
in (select v from @t group by v having count(*)>
1)
![](http://static.javashuo.com/static/loading.gif)
--b語句exists的sql寫法
![](http://static.javashuo.com/static/loading.gif)
select * from @t a
where exists(select
1 from @t
where id!=a.id and v=a.v)