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

# coll.union

> Returns a list of all unique elements from both input lists, treating them as sets.

## Description

Combines two lists and returns a new list containing all unique elements from both lists. Duplicates are automatically removed, treating the inputs as sets.

## Syntax

```cypher theme={null}
flex.coll.union(list1, list2)
```

## Parameters

| Parameter | Type | Required | Description     |
| --------- | ---- | -------- | --------------- |
| `list1`   | list | Yes      | The first list  |
| `list2`   | list | Yes      | The second list |

## Returns

**Type:** list

A new list containing all unique elements from both input lists. The order is not guaranteed.

## Examples

### Example 1: Basic Union

```cypher theme={null}
WITH [1, 2, 3] AS a, [3, 4, 5] AS b
RETURN flex.coll.union(a, b) AS result
```

**Output:**

```text theme={null}
result
--------------
[1, 2, 3, 4, 5]
```

### Example 2: Combining Tags from Multiple Nodes

```cypher theme={null}
MATCH (d1:Document {id: 'doc1'})
MATCH (d2:Document {id: 'doc2'})
RETURN flex.coll.union(d1.tags, d2.tags) AS allTags
```

### Example 3: Merging User Interests

```cypher theme={null}
MATCH (u:User)
WITH collect(u.interests) AS interestLists
RETURN reduce(result = [], list IN interestLists | 
    flex.coll.union(result, list)
) AS allUniqueInterests
```

### Example 4: Finding All Related Categories

```cypher theme={null}
MATCH (p:Product {id: 123})
MATCH (similar:Product)-[:SIMILAR_TO]-(p)
RETURN flex.coll.union(p.categories, similar.categories) AS combinedCategories
```

## Notes

* Automatically removes duplicates from the result
* Works with any comparable data types
* Order of elements in the result is not guaranteed
* Equivalent to mathematical set union operation
* Both lists are spread and deduplicated using Set

## See Also

* [coll.intersection](/udfs/flex/collections/intersection) - Find common elements between lists
* [sim.jaccard](/udfs/flex/similarity/jaccard) - Calculate similarity between sets

## Frequently Asked Questions

<AccordionGroup>
  <Accordion title="Does flex.coll.union remove duplicates?">
    Yes. The union function combines all input lists and returns only unique elements.
  </Accordion>

  <Accordion title="Can I pass more than two lists to union?">
    Yes. You can pass multiple lists as arguments to combine them all into a single deduplicated result.
  </Accordion>
</AccordionGroup>
