表
id name
1 苹果
2 梨
3 香蕉
4 香蕉
5 梨
正常查询
select * from Table_1
结果
id name
1 苹果
2 梨
3 香蕉
4 香蕉
5 梨
过滤重复1
select * from Table_1 a where not exists (select * from Table_1 where a.name=name and a.id<id)
id name
1 苹果
4 香蕉
5 梨
重点:a.id<id
过滤重复2
select * from Table_1 a where not exists (select * from Table_1 where a.name=name and a.id>id)
id name
1 苹果
2 梨
3 香蕉
重点:a.id>id