Skip to main content
Skip to main content

groupArrayIntersect

Return an intersection of given arrays (Return all items of arrays, that are in all given arrays).

Syntax

groupArrayIntersect(x)

Arguments

  • x — Argument (column name or expression).

Returned values

  • Array that contains elements that are in all arrays.

Type: Array.

Examples

Consider table numbers:

┌─a──────────────┐
│ [1,2,4]        │
│ [1,5,2,8,-1,0] │
│ [1,5,7,5,8,2]  │
└────────────────┘

Query with column name as argument:

SELECT groupArrayIntersect(a) AS intersection FROM numbers;

Result:

┌─intersection──────┐
│ [1, 2]            │
└───────────────────┘

groupArrayIntersect

Introduced in: v24.2

Return an intersection of given arrays (Return all items of arrays, that are in all given arrays).

Syntax

groupArrayIntersect(x)

Arguments

  • x — Argument (column name or expression). Any

Returned value

Returns an array that contains elements that are in all arrays. Array

Examples

Usage example

-- Create table with Memory engine
CREATE TABLE numbers (
    a Array(Int32)
) ENGINE = Memory;

-- Insert sample data
INSERT INTO numbers VALUES
    ([1,2,4]),
    ([1,5,2,8,-1,0]),
    ([1,5,7,5,8,2]);

SELECT groupArrayIntersect(a) AS intersection FROM numbers;
┌─intersection──────┐
│ [1, 2]            │
└───────────────────┘