You can use the UNION clause to combine result sets from multiple SELECT statements into a single result set.
Syntax
SELECT key1 FROM logstore1
UNION
SELECT key2 FROM logstore2
UNION
SELECT key3 FROM logstore3
Each SELECT statement in a UNION clause must have the same number of columns, and the corresponding columns must have the same data type.
Parameters
|
Parameter |
Description |
|
key |
The field name or column name. The names of key1, key2, and key3 can be different, but they must have the same data type. |
|
Logstore |
The name of the Logstore. |
Example
The following example calculates page views (PVs) per status code from two Logstores, website_log and internal-operation_log, and combines the results.
-
Query and analysis statement
* | SELECT status, count(*) AS PV FROM website_log GROUP BY status UNION SELECT status, count(*) AS PV FROM internal-operation_log GROUP BY status -
Query and analysis result: The result contains two columns, status and PV. The 24 records show page view counts for HTTP status codes such as 200, 206, 301, 400, and 401.