Home  >  Article  >  Database  >  What are the keywords that represent union in sql

What are the keywords that represent union in sql

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

In SQL, the keyword for union is UNION, which is used to combine the results of multiple SELECT statements into a single result set that contains all unique rows.

What are the keywords that represent union in sql

Keywords representing union in SQL

In SQL, the keywords representing union are:

  • UNION

Using UNION

UNION keyword is used for Combines the results of two or more SELECT statements into a single result set. The result set contains all unique rows from both input tables.

Syntax:

<code class="sql">SELECT 列名1, 列名2, ...
FROM 表名1
UNION
SELECT 列名1, 列名2, ...
FROM 表名2;</code>

For example:

<code class="sql">SELECT name, city
FROM table1
UNION
SELECT name, city
FROM table2;</code>

The above query will return table1 and table2 The name and city columns for all unique rows in the table.

The above is the detailed content of What are the keywords that represent union in sql. 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
Previous article:What does $ mean in sqlNext article:What does $ mean in sql