select * from tablename a where not exists(select 1 from tablename where type=a.type and id<a.id)