array_intersect function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Returns an array of the elements in the intersection of array1 and array2.

Syntax

array_intersect(array1, array2)

Arguments

  • array1: An ARRAY of any type with comparable elements.
  • array2: n ARRAY of elements sharing a least common type with the elements of array1.

Returns

An ARRAY of matching type to array1 with no duplicates and elements contained in both array1 and array2.

Examples

> SELECT array_intersect(array(1, 2, 3), array(1, 3, 3, 5));
 [1,3]