@filiberto
In Oracle SQL, the UNION operator is used to combine the results of two or more SELECT statements into a single result set. Here is an example of how to use UNION in Oracle SQL:
1 2 3 4 5 |
SELECT column1, column2 FROM table1 UNION SELECT column1, column2 FROM table2; |
In this example, the results of the two SELECT statements will be combined into a single result set, with duplicates removed. If you want to include duplicates in the result set, you can use the UNION ALL operator instead:
1 2 3 4 5 |
SELECT column1, column2 FROM table1 UNION ALL SELECT column1, column2 FROM table2; |
You can also use UNION with more than two SELECT statements, like this:
1 2 3 4 5 6 7 8 |
SELECT column1, column2 FROM table1 UNION SELECT column1, column2 FROM table2 UNION SELECT column1, column2 FROM table3; |
Remember that when using UNION, the number of columns returned by each SELECT statement must be the same, and the data types of the corresponding columns in each SELECT statement must be compatible.