--id是唯一吧?
--抢先贴一个数据
if object_id('ta') is not null drop table ta
go
create table ta(id int, title varchar(10), type int)
insert ta select 1, '记录1', 1
union all select 2, '记录2', 1
union all select 3, '记录3', 2
union all select 4, '记录4', 2
--抢先贴一个数据
if object_id('ta') is not null drop table ta
go
create table ta(id int, title varchar(10), type int)
insert ta select 1, '记录1', 1
union all select 2, '记录2', 1
union all select 3, '记录3', 2
union all select 4, '记录4', 2
from ta
where id in(select min(id) from ta group by type)
if object_id('ta') is not null drop table ta
go
create table ta(id int, title varchar(10), type int)
insert ta select 1, '记录1', 1
union all select 2, '记录2', 1
union all select 3, '记录3', 2
union all select 4, '记录4', 2---结果:
ID Title Type
2 记录2 1
4 记录4 2
select * from ta t where not exists(select * from ta where Type=t.type and ID<t.id )
select table1.* from table1 join (select type,min(title) title from table1 group by type ) a on table1.type=a.type
and table1.title=a.title