Home > Article > Daily Programming > What does union mean in mysql
UNION is used in MySQL to merge query results. It combines matching rows in multiple result sets and removes duplicate rows. The query in the example will merge matching rows in the name column in the employees and customers tables. UNION ALL does not remove duplicate rows, and the UNION operator is non-commutative, which means the order of the result set depends on the order of the SELECT statements.
UNION in MySQL
UNION is used in MySQL to merge the results of two or more SELECT statements. Keywords. It combines matching rows from two or more result sets into a new result set.
Syntax
<code class="sql">SELECT ... FROM ... UNION SELECT ... FROM ...</code>
Behavior
The UNION operator has the following behavior:
Example
<code class="sql">SELECT name FROM employees UNION SELECT name FROM customers;</code>
This query will merge the name column from the employees and customers tables and remove duplicate names.
UNION ALL
UNION ALL is a variant of UNION that does not delete duplicate rows.
<code class="sql">SELECT name FROM employees UNION ALL SELECT name FROM customers;</code>
This query will merge the name column from the employees and customers tables and keep duplicate names.
Note
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!