select (select ID from 表 where value in ('21') and ID=a.ID ) from 表 a where value in ('Tom')
try:
declare @t table(id int,value varchar(10))
insert into @t
select 1,'tom' union
select 1,'21' union
select 2,'tom' union
select 2,'23' union
select 3,'jack' union
select 3,'34' union
select 4,'test' union
select 4,'21' union
select 5,'test' union
select 5,'23' union
select 6,'xxx' union
select 6,'21'
select id from @t where value = 'tom'
and id in (select id from @t where value = '23')
---------------
(12 row(s) affected)
id
-----------
2
你的表设计的有问题!
ni 就说你需要什么样的结果吧