select t.* from tbl t where t.B=(select top 1 B from tbl where A=t.A)
--如: Select * from tb as x where B in (Select top 1 B from tb where A=x.A order by A,C)
A B C 的值不可能相同
表:a id name 11 aaaa 11 bbbb 11 cccc 22 dddd 22 eeee 22 ffff
如何将表中的相同id号的第一条记录取出来?即: id name 11 aaaa 22 ddddselect id1=identity(int,1,1),* into #t from a go select id,name from #t where id1 in(select min(id1) from #t group by id)select * from a b where name=(select top 1 name from a where id=b.id)
a,b,c不可能出现相同组合的话,那么可以select t.* from tbl t where rtrim(t.B)+','+rtrim(t.C)=(select top 1 rtrim(B) + ',' + rtrim(c) from tbl where A=t.A) 即三个字段一起比较
Select * from tb as x
where B in (Select top 1 B from tb where A=x.A
order by A,C)
id name
11 aaaa
11 bbbb
11 cccc
22 dddd
22 eeee
22 ffff
如何将表中的相同id号的第一条记录取出来?即:
id name
11 aaaa
22 ddddselect id1=identity(int,1,1),* into #t from a
go
select id,name from #t where id1 in(select min(id1) from #t group by id)select * from a b
where name=(select top 1 name from a where id=b.id)
即三个字段一起比较