Home >Database >Mysql Tutorial >What does union mean in mysql?

What does union mean in mysql?

下次还敢
下次还敢Original
2024-04-26 05:54:13635browse

UNION in MySQL is a union operator used to combine multiple result sets from different tables or queries into a new result set without duplicate rows. The columns in the new result set must have the same Data type and order, but UNION does not support aggregate functions and ORDER BY clauses.

What does union mean in mysql?

What is UNION in MySQL?

UNION is a union operator in MySQL that is used to combine multiple result sets from different tables or queries into one result set.

How to use UNION?

UNION syntax is as follows:

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

Example:

<code class="sql">-- 将表 A 和 B 中的 name 列组合为一个结果集
SELECT name
FROM A
UNION
SELECT name
FROM B</code>

Features of UNION:

  • Duplicate rows are not allowed in the result set.
  • The columns in the result set must have the same data type and order.

Limitations of UNION:

  • UNION does not support aggregate functions (e.g., SUM, COUNT).
  • UNION does not support ORDER BY clause.
  • UNION may be slower in performance than other union operators such as UNION ALL.

The above is the detailed content of What does union mean in mysql?. 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:Usage of in in mysqlNext article:Usage of in in mysql