SQL 查询表中某一字段不重复的所有数据

SQL 查询表中某一字段不重复的所有数据,第1张

1、创建测试表,

create table test_dis(id number, name varchar2(20), value number(10))

2、插入测试数据

insert into test_dis values(1,'a',123)

insert into test_dis values(2,'b',152)

insert into test_dis values(3,'c',123)

insert into test_dis values(4,'d',520)

insert into test_dis values(5,'e',300)

commit

3、查询表中全量数据,select t.*, rowid from test_dis t

4、编写sql,查询表中某一字段不重复的所有数据,可以发现只有id为2,4,5的记录查询出。

 select * from test_dis t where value in (select value from test_dis group by value having count(*)=1)

select t.* from 表 t

where exists(select * from 表 a where a.第二列 = t.第二列 group by a.第二列 having count(a.第二列) = 1)

测测吧,给个采纳就行了。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/6649548.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存