The INTERSECT clause combines the result sets of two SELECT statements and returns only rows that exist in both result sets.
Syntax
SELECT key1... FROM logstore1
INTERSECT
SELECT key2... FROM logstore2
-
Each SELECT clause must have the same number of columns, and the corresponding columns must be in the same order and have the same data type.
-
The INTERSECT clause returns only distinct rows from the final result set.
Parameters
|
Parameter |
Description |
|
key |
A field name, column name, or expression. You can specify different values for key1 and key2, but you must specify the same data types for them. |
|
Logstore |
The name of the Logstore. |
Examples
The internal-diagnostic_log Logstore records important logs, including log consumption latency, alerts, and log collection for each Logstore. The internal-operation_log Logstore records detailed logs, including operation logs for all resources in a Project. The following example uses the INTERSECT clause to find Logstores that generate both important and detailed logs.
-
Query and analysis statement
* | SELECT logstore FROM internal-operation_log INTERSECT SELECT logstore FROM internal-diagnostic_log -
Query and analysis result: The query returns three Logstores:
oss_log,website_log, andgame_log.