sql如何过滤到重复的数据 select DISTINCT(name) from 表A 这样可以把相同名称的过滤掉,但是这样只能查出

2025-03-25 20:52:53
推荐回答(5个)
回答1:

ORACLE:

select * from scott.stu
union (all)重复的去掉[intersect把相同的取出来][minus显示不相同的数]
select * from stu
-----------------------------------------------------------------
显示相同的数据
select name from stu intersect select name from stu1;
删除重复记录

Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)

回答2:

distinct 是对所有查询字段(一条记录一条记录)比较,相同只则保留一条
请关注 GROUP BY 子句语法

回答3:

如果你想过滤全表就写 select distinct * from A
如果要过滤几个字段就写 select distinct name,sex from A

回答4:

select DISTINCT name,sex from 表A 只会过滤掉name 和sex 都重复的数据。

回答5:

多字段的话要用group by
select name,sex from A group by name,sex