Home  >  Article  >  Database  >  What is the syntax of UNION operator in mysql

What is the syntax of UNION operator in mysql

WBOY
WBOYforward
2023-05-28 13:46:121252browse

What is the UNION operator in mysql?

The MySQL UNION operator is used to combine the results of two or more SELECT statements into a result set.

Multiple SELECT statements will delete duplicate data.

UNION operator syntax:

SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;

Note: The column name in the UNION result set is always equal to the first SELECT in UNION Column names in statements.

Usage example: Select all different countries (only different values) from the "Websites" and "app" tables

SELECT country FROM Websites
UNION
SELECT country FROM app
ORDER BY country;

The above is the detailed content of What is the syntax of UNION operator in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete