selelect id,name from a as a1 where not exists(select id from a where id <a1.id)
select min(ID),name from 表A group by name
直接用group by name就可以了,具體語句:select min=min(id),name from 表A group by name/*-- 結果 min name ----------- ---------- 1 a 2 b 5 c(所影响的行数为 3 行) --*/
--建立測試環境 Declare @Tb table(ID int,Name varchar(10)) insert @Tb select 1 ,'a' union all select 2 ,'b' union all select 3,'a' union all select 4,'b' union all select 5,'c'select * from @Tb --語句 select min=min(id),name from @Tb group by name
select min(id) as ID,name from 表A group by name
select * from 表A not exists(select 1 from 表A a where a.id<id and name=a.name )
上边的有问题 select * from test a where not exists(select 1 from test where id<a.id and names=a.names )
Select Min(ID)As ID ,NAME From A Group By NAME
Select Min(ID),NAME From A Group By NAME order by id
group by name
min name
----------- ----------
1 a
2 b
5 c(所影响的行数为 3 行)
--*/
Declare @Tb table(ID int,Name varchar(10))
insert @Tb select 1 ,'a'
union all select 2 ,'b'
union all select 3,'a'
union all select 4,'b'
union all select 5,'c'select * from @Tb
--語句
select min=min(id),name from @Tb group by name
)
)
From A
Group By NAME
From A
Group By NAME
order by id