{"id":18020713,"url":"https://github.com/inforkgodara/oracle-set-operators","last_synced_at":"2026-03-19T02:54:34.826Z","repository":{"id":110249951,"uuid":"273892416","full_name":"inforkgodara/oracle-set-operators","owner":"inforkgodara","description":"This repository contains the explanation of Oracle SQL set operators. UNION, UNION ALL, INTERSECT, MINUS, ","archived":false,"fork":false,"pushed_at":"2020-07-25T18:38:47.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T17:16:44.523Z","etag":null,"topics":["clause","inforkgodara","minus","oracle","oracle-database","oracle-set-operators","oracle-sql-database","oracle-sql-set-operator","set-operations","sql","sql-database","sql-script","union"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/inforkgodara.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-21T11:40:31.000Z","updated_at":"2023-06-21T03:44:24.000Z","dependencies_parsed_at":"2023-05-14T08:00:45.878Z","dependency_job_id":null,"html_url":"https://github.com/inforkgodara/oracle-set-operators","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/inforkgodara/oracle-set-operators","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inforkgodara%2Foracle-set-operators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inforkgodara%2Foracle-set-operators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inforkgodara%2Foracle-set-operators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inforkgodara%2Foracle-set-operators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inforkgodara","download_url":"https://codeload.github.com/inforkgodara/oracle-set-operators/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inforkgodara%2Foracle-set-operators/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28552132,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T20:59:07.572Z","status":"ssl_error","status_checked_at":"2026-01-18T20:59:02.799Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clause","inforkgodara","minus","oracle","oracle-database","oracle-set-operators","oracle-sql-database","oracle-sql-set-operator","set-operations","sql","sql-database","sql-script","union"],"created_at":"2024-10-30T06:07:24.584Z","updated_at":"2026-01-18T22:02:18.175Z","avatar_url":"https://github.com/inforkgodara.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Oracle Set Operators\n\nThe set operators are used to combine the results of two components queries into a single result. Queries containing set operators are called compound queries.\n\n## Setting up sample tables\n\nWe created two new tables departments and employees for the demonstration using Sample-tables.sql script. The SQL script is underfollowed.\n\n```\n-- Create DEPARTMENTS table\nCREATE TABLE DEPARTMENTS (\n  DEPARTMENT_ID   NUMBER(2) CONSTRAINT DEPARTMENTS_PK PRIMARY KEY,\n  DEPARTMENT_NAME VARCHAR2(14),\n  LOCATION        VARCHAR2(13)\n);\n\n-- Create EMPLOYEES table\nCREATE TABLE EMPLOYEES (\n  EMPLOYEE_ID   NUMBER(4) CONSTRAINT EMPLOYEES_PK PRIMARY KEY,\n  EMPLOYEE_NAME VARCHAR2(10),\n  JOB           VARCHAR2(9),\n  MANAGER_ID    NUMBER(4),\n  HIREDATE      DATE,\n  SALARY        NUMBER(7,2),\n  COMMISSION    NUMBER(7,2),\n  DEPARTMENT_ID NUMBER(2) CONSTRAINT EMP_DEPARTMENT_ID_FK REFERENCES DEPARTMENTS(DEPARTMENT_ID)\n);\n\n-- Insert data into DEPARTMENTS table\nINSERT INTO DEPARTMENTS VALUES (10,'ACCOUNTING','NEW YORK');\nINSERT INTO DEPARTMENTS VALUES (20,'RESEARCH','DALLAS');\nINSERT INTO DEPARTMENTS VALUES (30,'SALES','CHICAGO');\nINSERT INTO DEPARTMENTS VALUES (40,'OPERATIONS','BOSTON');\n\n-- Insert data into EMPLOYEES table\nINSERT INTO EMPLOYEES VALUES (7369,'SMITH','CLERK',7902,TO_DATE('17-12-1980','dd-mm-yyyy'),800,NULL,20);\nINSERT INTO EMPLOYEES VALUES (7499,'ALLEN','SALESMAN',7698,TO_DATE('20-2-1981','dd-mm-yyyy'),1600,300,30);\nINSERT INTO EMPLOYEES VALUES (7521,'WARD','SALESMAN',7698,TO_DATE('22-2-1981','dd-mm-yyyy'),1250,500,30);\nINSERT INTO EMPLOYEES VALUES (7566,'JONES','MANAGER',7839,TO_DATE('2-4-1981','dd-mm-yyyy'),2975,NULL,20);\nINSERT INTO EMPLOYEES VALUES (7654,'MARTIN','SALESMAN',7698,TO_DATE('28-9-1981','dd-mm-yyyy'),1250,1400,30);\nINSERT INTO EMPLOYEES VALUES (7698,'BLAKE','MANAGER',7839,TO_DATE('1-5-1981','dd-mm-yyyy'),2850,NULL,30);\nINSERT INTO EMPLOYEES VALUES (7782,'CLARK','MANAGER',7839,TO_DATE('9-6-1981','dd-mm-yyyy'),2450,NULL,10);\nINSERT INTO EMPLOYEES VALUES (7788,'SCOTT','ANALYST',7566,TO_DATE('13-JUL-87','dd-mm-rr')-85,3000,NULL,20);\nINSERT INTO EMPLOYEES VALUES (7839,'KING','PRESIDENT',NULL,TO_DATE('17-11-1981','dd-mm-yyyy'),5000,NULL,10);\nINSERT INTO EMPLOYEES VALUES (7844,'TURNER','SALESMAN',7698,TO_DATE('8-9-1981','dd-mm-yyyy'),1500,0,30);\nINSERT INTO EMPLOYEES VALUES (7876,'ADAMS','CLERK',7788,TO_DATE('13-JUL-87', 'dd-mm-rr')-51,1100,NULL,20);\nINSERT INTO EMPLOYEES VALUES (7900,'JAMES','CLERK',7698,TO_DATE('3-12-1981','dd-mm-yyyy'),950,NULL,30);\nINSERT INTO EMPLOYEES VALUES (7902,'FORD','ANALYST',7566,TO_DATE('3-12-1981','dd-mm-yyyy'),3000,NULL,20);\nINSERT INTO EMPLOYEES VALUES (7934,'MILLER','CLERK',7782,TO_DATE('23-1-1982','dd-mm-yyyy'),1300,NULL,10);\n```\n\n## UNION\n\nThe UNION set operator returns all distinct rows selected by either query. That means any duplicate rows will be removed.\n\nIn the example below, notice there is only a single row each for departments 20 and 30, rather than two each.\n\n```\nSELECT DEPARTMENT_ID, DEPARTMENT_NAME\nFROM   DEPARTMENTS\nWHERE  DEPARTMENT_ID \u003c= 30\nUNION\nSELECT DEPARTMENT_ID, DEPARTMENT_NAME\nFROM   DEPARTMENTS\nWHERE  DEPARTMENT_ID \u003e= 20\nORDER BY 1;\n\nDEPARTMENT_ID DEPARTMENT_NAM\n------------- --------------\n           10 ACCOUNTING\n           20 RESEARCH\n           30 SALES\n           40 OPERATIONS\n\n4 rows selected.\n```\n\n## UNION ALL\n\nThe UNION ALL set operator returns all rows selected by either query. That means any duplicates will remain in the final result set.\n\nIn the example below, notice there are two rows each for departments 20 and 30.\n\n```\nSELECT DEPARTMENT_ID, DEPARTMENT_NAME\nFROM   DEPARTMENTS\nWHERE  DEPARTMENT_ID \u003c= 30\nUNION ALL\nSELECT DEPARTMENT_ID, DEPARTMENT_NAME\nFROM   DEPARTMENTS\nWHERE  DEPARTMENT_ID \u003e= 20\nORDER BY 1;\n\nDEPARTMENT_ID DEPARTMENT_NAM\n------------- --------------\n           10 ACCOUNTING\n           20 RESEARCH\n           20 RESEARCH\n           30 SALES\n           30 SALES\n           40 OPERATIONS\n\n6 rows selected.\n```\n\n## INTERSECT\n\nThe INTERSECT set operator returns all distinct rows selected by both queries. That means only those rows common to both queries will be present in the final result set.\n\nIn the example below, notice there is one row each for departments 20 and 30, as both these appear in the result sets for their respective queries.\n\n```\nSELECT DEPARTMENT_ID, DEPARTMENT_NAME\nFROM   DEPARTMENTS\nWHERE  DEPARTMENT_ID \u003c= 30\nINTERSECT\nSELECT DEPARTMENT_ID, DEPARTMENT_NAME\nFROM   DEPARTMENTS\nWHERE  DEPARTMENT_ID \u003e= 20\nORDER BY 1;\n\nDEPARTMENT_ID DEPARTMENT_NAM\n------------- --------------\n           20 RESEARCH\n           30 SALES\n\n2 rows selected.\n```\n\n## MINUS\n\nThe MINUS set operator returns all distinct rows selected by the first query but not the second. This is functionally equivalent to the ANSI set operator EXCEPT DISTINCT.\n\nIn the example below, the first query would return departments 10, 20, 30, but departments 20 and 30 are removed because they are returned by the second query. This leaves a single rows for department 10.\n\n```\nSELECT DEPARTMENT_ID, DEPARTMENT_NAME\nFROM   DEPARTMENTS\nWHERE  DEPARTMENT_ID \u003c= 30\nMINUS\nSELECT DEPARTMENT_ID, DEPARTMENT_NAME\nFROM   DEPARTMENTS\nWHERE  DEPARTMENT_ID \u003e= 20\nORDER BY 1;\n\nDEPARTMENT_ID DEPARTMENT_NAM\n------------- --------------\n           10 ACCOUNTING\n\n1 row selected.\n```\n\nNote: The ORDER BY clause is applied to all rows returned in the final result set. Columns in the ORDER BY clause can be referenced by column names or column aliases present in the first query of the statement, as these carry through to the final result set. Typically, you will see people use the column position as it is less confusing when the data is sourced from different locations for each query block.\n\n```\nSELECT EMPLOYEE_ID, EMPLOYEE_NAME\nFROM   EMPLOYEES\nWHERE  DEPARTMENT_ID = 10\nUNION ALL\nSELECT DEPARTMENT_ID, DEPARTMENT_NAME\nFROM   DEPARTMENTS\nWHERE  DEPARTMENT_ID \u003e= 20\nORDER BY EMPLOYEE_ID;\n\nEMPLOYEE_ID EMPLOYEE_NAME\n----------- --------------\n         20 RESEARCH\n         30 SALES\n         40 OPERATIONS\n       7782 CLARK\n       7839 KING\n       7934 MILLER\n\n6 rows selected.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finforkgodara%2Foracle-set-operators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finforkgodara%2Foracle-set-operators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finforkgodara%2Foracle-set-operators/lists"}