sql 过滤重复数据

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

发布了252 篇原创文章 · 获赞 94 · 访问量 54万+

猜你喜欢

转载自blog.csdn.net/cplvfx/article/details/103366753
今日推荐