2个select 查询后取结果集问题

Dragon 2011-10-19 06:38:09
请各位高手,高高手帮忙解决如下问题:

我有2个select 语句
select name from tableA (结果有5个: A, B, C, D,E)
select name from tableB (结果有7个: E, F, C, D,E, R, X)

而我需要得到的是 ( A, B, E,F, R, X)


谢谢啦!!!
...全文
216 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
NLP爱好者 2011-10-26
  • 打赏
  • 举报
回复

路过了,学习
m540920181 2011-10-26
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sky_4k_ppm 的回复:]
(select name from tableA union all select name from tableB)
minus
(select name from tableA a,tableB b where a.name=b.name)
[/Quote]

这个是对的,如果直接使用minus你是得不到所要的结果的
zhangzhipeng2011 2011-10-26
  • 打赏
  • 举报
回复
我做出了个答案不知符不符合要求



SQL> select name from taba;

NAME
----------------
A
B
C
D
E

SQL> select name from tabb;

NAME
----------------
E
F
C
D
E
R
X

已选择7行。

SQL> edit
已写入 file afiedt.buf

1 select name from tabb where rowid not in
2 ( select max(rowid) from tabb where name in
3 ( SELECT NAME FROM TABB INTERSECT SELECT NAME FROM TABA )
4 group by name
5 )
6 union
7 ( select name from taba
8 minus
9 select name from tabb
10* )
SQL> /

NAME
----------------
A
B
E
F
R
X

已选择6行。

SQL>



  • 打赏
  • 举报
回复
俩表有联系么 ?
xiaobn_cn 2011-10-20
  • 打赏
  • 举报
回复
1楼和5楼正解,直接minus就可以了
benson_xi 2011-10-20
  • 打赏
  • 举报
回复
(select name from tableA union all select name from tableB)
minus
(select name from tableA a,tableB b where a.name=b.name)
习惯孤独 2011-10-20
  • 打赏
  • 举报
回复
路过,学习下
YeHuai1991 2011-10-20
  • 打赏
  • 举报
回复
select sst.* from (
select t2.name from tableA t2 where t2.name not in (select t1.name from tableB t1)
union
select t4.name from tableB t4 where t4.name not in (select t5.name from tableA t5)
) sst
SKY_4K_PPM 2011-10-19
  • 打赏
  • 举报
回复
(select name from tableA union all select name from tableB)
minus
(select name from tableA a,tableB b where a.name=b.name)
noteasytoregister 2011-10-19
  • 打赏
  • 举报
回复
select * from (
select name from tableA
union
select name from tableB
) t
minus
select * from (
select name from tableA
intersect
select name from tableB
) t2
noteasytoregister 2011-10-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 noteasytoregister 的回复:]

SQL code
select name from tableA --(结果有5个: A, B, C, D,E)
union
select name from tableB --(结果有7个: E, F, C, D,E, R, X)
[/Quote]
不好意思,错了!
noteasytoregister 2011-10-19
  • 打赏
  • 举报
回复
select name from tableA --(结果有5个: A, B, C, D,E)
union
select name from tableB --(结果有7个: E, F, C, D,E, R, X)
yejihui9527 2011-10-19
  • 打赏
  • 举报
回复
规律 是不要 3-5吗?还是重复不要
重复不要
minus 或者 not in

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧