Oracle的集合操作

來源:互聯網
上載者:User

關鍵字:

1、UNION:並集,所有的內容都查詢,重複的顯示一次;

2、UNION ALL:並集,所有的內容都顯示,包括重複的;

3、INTERSECT:交集,只顯示重複的;

4、MINUS:差集,只顯示對方沒有的(跟順序是有關係的)

例子:

在scott使用者下,建立表emp2,該表只包含emp中20部門員工的資訊:

代碼:create table emp2 as select * from emp where deptno=20;

先看下emp和emp2兩個表的區別:

[emp表結構及內容]

 

[emp2表結構及內容]

~ 驗證UNION及UNION ALL

 UNION:select * from emp UNION select * from emp2;/*使用此語句,重複的內容不再顯示*/

 

 UNION ALL:select * from emp UNION ALL select * from emp2;/*使用此語句,重複的內容依然顯示*/

~ 驗證INTERSECT

 INTERSECT:select * from emp INTERSECT select * from emp2;/*使用此語句,只顯示兩個表中彼此重複的記錄*/


~ 驗證MINUS

 MINUS:select * from emp MINUS select * from emp2;/*使用此語句,返回顯示差異的記錄*/

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.