Home > Database > Oracle > What does union mean in oracle?

What does union mean in oracle?

下次还敢
Release: 2024-05-02 23:21:17
Original
1155 people have browsed it

UNION is a data manipulation language command that vertically combines the results of two or more SELECT statements but retains only unique rows. It requires that the result sets of the merged SELECT statements have the same number of columns and data types, and can only handle compatible data types (for example, you cannot combine numeric columns with string columns).

What does union mean in oracle?

UNION in Oracle

What is UNION?

UNION is a Data Manipulation Language (DML) command that combines the results of two or more SELECT statements into a new result set.

How UNION works

The UNION operation vertically combines the result sets of two SELECT statements. However, it only retains unique rows. This means that it automatically removes duplicate rows that appear in the result set.

UNION syntax

<code>SELECT 列名1, 列名2, ...
FROM 表名1
UNION
SELECT 列名1, 列名2, ...
FROM 表名2;</code>
Copy after login

UNION usage

UNION can be used in various scenarios, such as:

  • Combine result sets from different tables
  • Remove duplicate rows from the same table
  • Find values ​​that exist or do not exist in the table

Example

Consider the following example:

<code>SELECT employee_id, employee_name
FROM employees
UNION
SELECT customer_id, customer_name
FROM customers;</code>
Copy after login

This UNION operation creates a result set containing the ID cards and names of all employees and customers.

Notes

You need to pay attention to the following when using UNION:

  • UNION requires that the result set of the merged SELECT statement has the same number of columns. and data type.
  • UNION does not sort the result set. To sort the results, use the ORDER BY clause.
  • UNION can only handle compatible data types. For example, you cannot combine numeric columns with string columns.

The above is the detailed content of What does union mean in oracle?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template