ORACLE
ORACLE OPERATORS
UNION
UNION ALL
INTERSECT
MINUS
ORACLE TUTORIAL
Oracle Introduction
What Is Oracle
ORACLE TABLES
Create Tables
Create Table As
Alter Table
Drop Table
Global Temorary Tables
Local Temorary Tables
ORACLE VIEWS
Create View
ORACLE QUERIES
SELECT
INSERT
INSERT ALL
UPDATE
DELETE
TRUNCATE TABLE
ORACLE CLAUSES
DISTINCT
FROM
ORDER BY
GROUP BY
HAVING
ORACLE JOINS
INNER JOIN
OUTER JOIN
EQUI JOIN
SELF JOIN
CROSS JOIN
ANTI JOIN
SEMI JOIN
ORACLE ADVANCE
PROCEDURES
FUNCTION
CURSOR
TRIGGER

UNION



Oracle - Union


UNION operator is used to combine the result sets of two or more Oracle SELECT statements. It combines the both SELECT statement and removes duplicate rows between them.

Each SELECT statement within the UNION operator must have the same number of fields in the result sets with similar data types.


Syntax :

SELECT expression1, expression2, ... expression_n  
FROM table1  
WHERE conditions  
UNION  
SELECT expression1, expression2, ... expression_n  
FROM table2  
WHERE conditions;   

Parameters :


  • expression1, expression2, ... expression_n: It specifies the columns that you want to retrieve.

  • table1, table2: it specifies the tables from where you retrieve the records.

  • conditions: it specifies the conditions that must be fulfilled for the records to be selected.

    Note: The number of expressions must be same in both of the SELECT statements.


    Oracle UNION Example: (Fetch single field)


    SELECT supplier_id  
    FROM suppliers  
    UNION  
    SELECT supplier_id  
    FROM order_details  
    

    Output :
    Supplier_ID
    1
    2
    3
    20
    21
    22
    25
    28
    30
    31
    More than 10 rows available.Increase rows selector to view more rows

    In this example, supplier_id is defined in both of the table "suppliers" and "order_details". After the UNION, it would appear once in the result set because Oracle UNION operator removes duplicate sets.


    Note: If you don't want to remove duplicates, use Oracle UNION ALL operator.


    Oracle UNION Example: (Using ORDER BY)


    The Oracle UNION operator can be used with ORDER BY clause to orders the results of the query.

    SELECT supplier_id, supplier_name  
    FROM suppliers  
    WHERE supplier_id <= 20  
    UNION  
    SELECT s_id, s_name  
    FROM shopkeepers  
    WHERE s_name = 'dhirubhai'  
    ORDER BY 1;  
    

    Output :
    Supplier_IDSupplier_Name
    1Bata shoes
    1dhirubhai
    2Kingfisher
    3VOJO
    20Google

    In the above example, result is sorted by supplier_name/s_name in ascending order, as denoted by ORDER BY 1.



    What Is Oracle

    What Is Oracle

    posted on 2019-11-29 01:11:21 - ORACLE Tutorials


    TRIGGER

    ORACLE - Trigger

    posted on 2019-11-28 22:14:22 - ORACLE Tutorials


    CURSOR

    ORACLE - Cursor

    posted on 2019-11-28 22:13:54 - ORACLE Tutorials


    MySQL TRIGGERS

    MySQL - Triggers

    posted on 2019-11-29 21:44:07 - mysql Tutorials


    Grant_ Revoke Privilege

    MySQL - Grant_ Revoke Privilege

    posted on 2019-11-26 23:15:04 - mysql Tutorials


    MySQL Vs SQL

    MySQL Vs SQL

    posted on 2019-11-25 05:02:26 - mysql Tutorials