Home >Database >SQL >The keyword representing union in sql is

The keyword representing union in sql is

下次还敢
下次还敢Original
2024-05-01 23:42:43558browse

The keyword representing union in SQL is UNION. The UNION operator combines rows from two or more tables into a single result set, retaining only unique rows. The syntax is: SELECT column1, column2, ... FROM table1 UNION SELECT column1, column2, ... FROM table2;. For example, to find all the names of students and teachers, we can use the following query: SELECT name FROM students UNION SELECT name FROM teachers;.

The keyword representing union in sql is

The keyword representing union in SQL: UNION

Union is an operator in SQL. Used to merge rows from two or more tables into a single result set, retaining only unique rows. The UNION keyword is used to perform this operation.

Syntax:

<code class="sql">SELECT column1, column2, ...
FROM table1
UNION
SELECT column1, column2, ...
FROM table2;</code>

Example:

Suppose there are two tables, students and teachers. We want to find the names of all students and teachers:

<code class="sql">SELECT name
FROM students
UNION
SELECT name
FROM teachers;</code>

The result will contain the names of students and teachers without duplicates.

The above is the detailed content of The keyword representing union in sql is. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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