UNION ALL is used in Oracle to merge result sets from different tables or subqueries while retaining duplicate rows. The specific usage is as follows: merge rows in different tables: SELECT FROM table 1 UNION ALL SELECT FROM table 2 merge duplicate rows in the same table: SELECT FROM table UNION ALL SELECT FROM table
Usage of UNION ALL syntax in Oracle
UNION ALL is an operator in Oracle used to merge multiple SELECT statement result sets. It allows you to combine results from multiple tables or subqueries into a single result set without eliminating duplicate rows.
Syntax:
<code class="sql">SELECT ... UNION ALL SELECT ... [UNION ALL SELECT ...]</code>
Usage:
The UNION ALL operator has two main uses:
<code class="sql">SELECT * FROM employees UNION ALL SELECT * FROM customers;</code>
This will return a result set containing all rows from the employees table and customers table.
<code class="sql">SELECT * FROM employees UNION ALL SELECT * FROM employees;</code>
This will return a result set containing all rows in the employees table, including duplicate rows.
Note:
The above is the detailed content of How to use union all in oracle. For more information, please follow other related articles on the PHP Chinese website!