oracle的union视图问题
答案:2 悬赏:70
解决时间 2021-02-11 16:25
- 提问者网友:房东的猫
- 2021-02-11 05:44
oracle的union视图问题
最佳答案
- 二级知识专家网友:青灯壁纸妹
- 2021-02-11 06:28
union 是合并重复项的
比如视图A
id value
1 1
2 2
3 3
视图B
id value
1 2
1 1
union后,只保留一个
id value
1 1
最后结果只有四条
你要保留所有要用union all
这样结果才是五条记录
select * from A
union all
select * from B
比如视图A
id value
1 1
2 2
3 3
视图B
id value
1 2
1 1
union后,只保留一个
id value
1 1
最后结果只有四条
你要保留所有要用union all
这样结果才是五条记录
select * from A
union all
select * from B
全部回答
- 1楼网友:冷眼_看世界
- 2021-02-11 07:16
**补充:你仔细看看我的回答***
你下面的想法是错误的
select * from a minus select * from b ={1,2,3,6,7,8}
*****************************
sql> select * from test001;
name
----------
1
2
3
4
5
sql> select * from test002;
name
----------
4
5
6
7
8
sql> select * from test001 minus select * from test002;
name
----------
1
2
3
sql> select * from test001 union select * from test002;
name
----------
1
2
3
4
5
6
7
8
按照上面的结果,查询ab交集只需要
select * from a minus (select * from a minus select * from b);
sql> select * from test001 minus (select * from test001 minus select * from test002);
name
----------
4
5
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯