mysql union
时间: 2023-10-26 13:49:45 浏览: 35
The UNION operator in MySQL is used to combine the results of two or more SELECT statements into a single result set. The syntax for the UNION operator is as follows:
SELECT column1, column2, ... FROM table1
UNION
SELECT column1, column2, ... FROM table2
The result of this query will be a combination of the results of the two SELECT statements. The columns in the result set will be the same as those in the first SELECT statement, with any additional columns from the second SELECT statement added to the end.
Note that the UNION operator automatically removes any duplicate rows from the result set. If you want to include duplicate rows, you can use the UNION ALL operator instead:
SELECT column1, column2, ... FROM table1
UNION ALL
SELECT column1, column2, ... FROM table2
This will include all rows from both tables, even if there are duplicates.