A UNION clause is used to combine the analysis results of multiple SELECT statements.
Syntax
SELECT key1 FROM logstore1
UNION
SELECT key2 FROM logstore2
UNION
SELECT key3 FROM logstore3
Important
All SELECT statements in a UNION clause must have the same number of columns, and their corresponding columns must have the same data type.
Parameters
|
Parameter |
Description |
|
key |
The field name or column name. The values of the key1, key2, and key3 parameters must be of the same data type. You can specify different field names or column names. |
|
Logstore |
The name of the Logstore. |
Example
This example calculates the page view (PV) count for each status code from two Logstores, website_log and internal-operation_log, and combines the results.
-
Query
* | SELECT status, count(*) AS PV FROM website_log GROUP BY status UNION SELECT status, count(*) AS PV FROM internal-operation_log GROUP BY status -
Results
