> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# cardinality

> Returns the number of elements in an array.

Returns the number of elements in an array. The result type is INT. If the input parameter is NULL, the result is also NULL. Null elements are counted in the length.

It is the alias of [array\_length()](/documents/4.2/sql-reference/sql-functions/array-functions/array_length.md).

This function is supported from v3.0 onwards.

## Syntax

```Haskell theme={null}
INT cardinality(any_array)
```

## Parameters

`any_array`: the ARRAY value from which you want to retrieve the number of elements.

## Return value

Returns an INT value.

## Examples

```plain text theme={null}
mysql> select cardinality([1,2,3]);
+-----------------------+
|  cardinality([1,2,3]) |
+-----------------------+
|                     3 |
+-----------------------+
1 row in set (0.00 sec)

mysql> select cardinality([1,2,3,null]);
+------------------------------+
| cardinality([1, 2, 3, NULL]) |
+------------------------------+
|                            4 |
+------------------------------+

mysql> select cardinality([[1,2], [3,4]]);
+-----------------------------+
|  cardinality([[1,2],[3,4]]) |
+-----------------------------+
|                           2 |
+-----------------------------+
1 row in set (0.01 sec)
```

## keyword

CARDINALITY, ARRAY\_LENGTH, ARRAY


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.