array_distinct
从数组中删除重复的元素。
语法
array_distinct(array)
参数
array
: 要从中删除重复元素的数组。仅支持 ARRAY 数据类型。
返回值
返回一个数组。
使用说明
-
返回的数组的元素排序可能与您指定的数组的元素排序不同。
-
返回的数组的元素与您指定的数组的元素的数据类型相同。
示例
在本节中,以下表用作示例
mysql> select * from test;
+------+---------------+
| c1 | c2 |
+------+---------------+
| 1 | [1,1,2] |
| 2 | [1,null,null] |
| 3 | NULL |
| 4 | [null] |
+------+---------------+
从列c2
中删除重复值。
mysql> select c1, array_distinct(c2) from test;
+------+----------------------+
| c1 | array_distinct(`c2`) |
+------+----------------------+
| 1 | [2,1] |
| 2 | [null,1] |
| 3 | NULL |
| 4 | [null] |
+------+----------------------+