SETCONTAINSANY() function
SETCONTAINSANY()
tests membership of a set of values within a set. It returns true if any of the members of testset
exist in targetset
Syntax
setcontainsany(targetset, testset)
Arguments
Argument | Description | Data type | Return value |
---|---|---|---|
targetset | The set in which the members of testset are being tested for membership. | stringset or idset | |
testset | The set of values to test membership for in the targetset. | Match targetset |
Returns
Data type | Value |
---|---|
bool | True if any member of testset exists within targetset |
Examples
Testing set membership in the select list
This query returns true
create table segments
(_id id, segment stringset);
insert into segments(_id, segment)
values (1, ['RED', 'BLUE', 'GREEN']);
select setcontainsany(segment, ['BLUE', 'RED']) as HasBlueOrRed
from segments;
-- Returns: true
Testing set membership as a where clause filter
create table segments
(_id id, segment stringset);
insert into segments(_id, segment)
values (1, ['RED', 'BLUE', 'GREEN']);
select _id, segment from segments where setcontainsany(segment, ['BLUE', 'RED']);
+-----+------------------+
| _id | segment |
+-----+------------------+
| 1 | [RED BLUE GREEN] |
+-----+------------------+