intersection() Function

Returns only those elements that appear in all of the given arrays.

Syntax

intersection( array1, array2, … )

array1: (Any Type Array) Array to intersect.

array2: (Any Type Array) Array to intersect.

Returns

Any Type Array, matching the type of the inputs

Examples


Find the values that are common in two integer arrays:

intersection({1, 2, 3, 4}, {3, 4, 5, 6}) returns an array with 3, 4

Find the values that are common in two text arrays. Values are matched case sensitively:

intersection({"a", "b", "A"}, {"a", "c"}) returns an array with a

NOTE: To match items case insensitively, use the lower() function on both inputs.

A value is returned for each match:

intersection({"a", "b", "a"}, {"a"}) returns an array with a, a

The types of the arrays must match:

intersection({"a"}, {1}) returns the following error message: Invalid types, can only act on data of the same type.

NOTE: Use either the conversion functions or the cast() function to convert to the appropriate type.

When one of the arrays is empty, or no common values are found, an empty array of the same type as the inputs is returned:

intersection({1}, tointeger({})) returns an empty integer array

intersection({"a"}, {"b"}) returns an empty text array

An unlimited number of arrays can be compared, and the values common to all of them are returned:

intersection({1, 2}, {2, 3}, {2, 4}) returns an array with 2

Null values in the array are matched and returned:

intersection({1, null, 3}, {1, null, 4}) returns an array with 1, <null>

Scalar inputs are cast to arrays:

intersection(1, 1) returns an array with 1

Open in Github Built: Fri, Nov 04, 2022 (07:10:52 PM)

On This Page

FEEDBACK