tencent cloud

Cloud Log Service

UNION Syntax

Download
Focus Mode
Font Size
Last updated: 2026-05-06 19:04:04
The UNION syntax is used to merge analysis results of multiple SELECT statements.

Syntax Format

* | SELECT [column name(KEY)] FROM table1 UNION SELECT [column name(KEY)] FROM table2
The analysis results of each SELECT statement should have the same number of columns and the same field types to be merged.
If the SELECT result contains duplicate rows, UNION retains only one instance of each by default. To retain all, use UNION ALL.

Syntax Example

Merge two tables that have only one column. Among them, the first table has only one row with the value 13, and the second table has two rows with values 42 and 13. Merge the duplicate rows.
* | SELECT * FROM (VALUES 13)
UNION
SELECT * FROM (VALUES 42,13)
Return result:



Merge two tables that have only one column. Among them, the first table has only one row with the value 13, and the second table has two rows with values 42 and 13. Do not merge the duplicate rows.
* | SELECT * FROM (VALUES 13)
UNION ALL
SELECT * FROM (VALUES 42,13)
Return result:





Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback