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
Notice Each SELECT statement in a UNION clause must have the same number of columns. The values of the columns in the same position must be of 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

Calculate the number of the page views (PVs) for each status code from the website_log Logstore and the internal-operation_log Logstore. All queried and analyzed data is combined and returned at the same time.

  • Query 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 resultunion