# How to union two list fields in the same Database?

**URL:** <https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467>\
**Category:** Get Help\
**Tags:** formulas\
**Created:** [January 30, 2022, 5:06pm UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467 "2022-01-30T17:06:42Z")\
**Posts on this page:** 19\
**Page:** 2

<div class="post-metadata">

**Author:** ![masp](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@masp](https://community.fibery.io/u/masp)\
**Post date:** [February 1, 2022, 11:05pm UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/21 "2022-02-01T23:05:52Z")

</div>

Sorry: I guess bringing up Reduce() and Map() was a bit off-topic, but yes: Join() is a specific example of a Map() + Reduce(), where the entities are mapped to strings and then reduced with string concatenation. So if you exposed Map() and Reduce() functions to us directly then we could implement our own Join(), eg: as Reduce(Map([Tags], ToText), ‘+’) but we could also implement any (supported) Map() function or any supported Reduce() function, or any combination, which would be very powerful (as long as you support more than ToText() in Map(), and more than ‘+’ in Reduce()).

---

<div class="post-metadata">

**Author:** ![masp](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@masp](https://community.fibery.io/u/masp)\
**Post date:** [February 2, 2022, 1:22am UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/22 "2022-02-02T01:22:53Z")

</div>

So I guess collections are sets, in which case yes they’ll be unique by definition, and you would just need to supply (off the top of my head) Union(), Intersect(), Diff() functions: and I guess also Complement() if the universe for that particular collection was finite and enumerated.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 2, 2022, 7:11am UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/23 "2022-02-02T07:11:25Z")

</div>

My gut feeling is that union is the most useful. I’m not sure how many users would need intersect, diff or complement.  
Perhaps community members will come up with use cases 🙂

---

<div class="post-metadata">

**Author:** ![masp](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@masp](https://community.fibery.io/u/masp)\
**Post date:** [February 2, 2022, 5:18pm UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/24 "2022-02-02T17:18:41Z")

</div>

Yes, 100%. Union() would solve my immediate problem: I just figured if you’re going to add that then you might consider adding (at least) Intersect() and Diff() at the same time, because together those operations would enable a lot more use cases than Union() alone.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 2, 2022, 5:42pm UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/25 "2022-02-02T17:42:45Z")

</div>

Can you provide some example use cases that need intersect or diff. It’s always interesting to hear what people want to achieve.

---

<div class="post-metadata">

**Author:** ![masp](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@masp](https://community.fibery.io/u/masp)\
**Post date:** [February 3, 2022, 10:58pm UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/26 "2022-02-03T22:58:05Z")

</div>

Thanks! What are References? I can’t find an explanation of them in the UI or docs; just lots of people commenting on how much they like them!

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [February 3, 2022, 11:06pm UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/27 "2022-02-03T23:06:29Z")

</div>

“References” would be links to entities in a Rich Text field.  
In an entity that has been linked, all the links to it are shown in a collection in the entity view:

![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/5/5ae7ca4d515fe7cf5545f8949527e89f0e853186.png)

Or possibly another name for Relation fields / collections?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 4, 2022, 12:17am UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/28 "2022-02-04T00:17:53Z")

</div>

Does this help?

> **[Bi-Directional Hypertext Links in Fibery](https://help.fibery.io/en/articles/4455989-bi-directional-hypertext-links-in-fibery)**
>
> How to use bi-directional links in Fibery to connect all the things.

---

<div class="post-metadata">

**Author:** ![masp](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@masp](https://community.fibery.io/u/masp)\
**Post date:** [February 4, 2022, 2:24am UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/29 "2022-02-04T02:24:19Z")

</div>

Yes, thanks: I get it now: although I guess Reference isn’t surfaced as an official Collection in the Database (or any other) view of a referenced Database?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 4, 2022, 8:14am UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/30 "2022-02-04T08:14:09Z")

</div>

See here for a backdoor API to programmatically access references

> [@Make "creation context" available to scripts](https://community.fibery.io/t/make-creation-context-available-to-scripts/2385):
>
> Scenario: I am typing notes in the richtext Description field of a “Meeting Notes” entity. When I create a new Task entity inline (via Ctrl+E), and I want a script to automatically set some fields in the new Task entity upon creation, and it has existing relations that are relevant. But the script needs to know the context in which this new Task entity is created – i.e., this “Meeting Notes” entity is a kind of “parent context” for its creation. The script needs this parent-context to get the…

---

<div class="post-metadata">

**Author:** ![masp](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@masp](https://community.fibery.io/u/masp)\
**Post date:** [February 4, 2022, 7:02pm UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/31 "2022-02-04T19:02:10Z")

</div>

Thanks! Very useful.

---

<div class="post-metadata">

**Author:** ![Miklos\_Beothy](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/miklos_beothy/32/5300_2.png) [@Miklos\_Beothy](https://community.fibery.io/u/Miklos_Beothy)\
**Post date:** [July 21, 2022, 8:57am UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/32 "2022-07-21T08:57:09Z")

</div>

Hey Chris! I would definitely need this feature (allowing combining entities from the same type). Is this already on your roadmap? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![BertrandC](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/bertrandc/32/4828_2.png) [@BertrandC](https://community.fibery.io/u/BertrandC)\
**Post date:** [October 27, 2022, 9:38pm UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/33 "2022-10-27T21:38:14Z")

</div>

+1 on this `union()` feature; it really could be a game changer (especially on roadmap/PM topics) to merge same entity type in a single place even when feeded from several sources.  
Automation can be used as workaround, but it requires to limit/restrict the way to use it to a strict workflow (e.g. relations between entities to be set in a certain order) that may not be always be followed.

---

<div class="post-metadata">

**Author:** ![Matt\_Blais](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/matt_blais/32/1464_2.png) [@Matt\_Blais](https://community.fibery.io/u/Matt_Blais)\
**Post date:** [October 28, 2022, 1:16am UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/34 "2022-10-28T01:16:16Z")

</div>

I have a working demo. The only real downside is that the Child’s “Collected Tags” collection, which includes both the Parent’s and Child’s tags, is not read-only - it is a regular many-to-many relation that is maintained by Automation.

This is a UI issue, in that it would be confusing for people who make changes directly to this collection instead of changing the Child’s or Parent’s “My Tags” collections directly.

* * *

Here are very simple Parent and Child DBs. Each one has its own “My Tags” collection (linked to the same Tags DB):

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/c/cf82c7db2536bc08525850de59da9a268d6aabce.png)

The Child also has a Lookup of its Parent’s “My Tags” collection (“Parent Tags”).

There is a separate automation for each possible change (link or unlink) to the Child’s “My Tags” or “Parent Tags” collection, and these four automations all do exactly the same thing: First unlink everything from the "Collected Tags’ collection, then rebuild it by linking everything from the Child’s “My Tags” collection and the “Parent Tags” collection:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/e/eb18c43839468b4b743355e7940d04de545e6f12.png)

There is no issue with duplication of Tags/links - that can’t happen because each Tag entity is unique, and if it is linked in to a collection twice, it is still just a single link to a unique entity.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [October 28, 2022, 6:09am UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/35 "2022-10-28T06:09:01Z")

</div>

> [@Matt\_Blais](#):
>
> The only real downside is that the Child’s “Collected Tags” collection, which includes both the Parent’s and Child’s tags, is not read-only

Now that it is possible to hide fields, there is a workaround for this: add a formula field which is simply the name of the other field (i.e. [Collected Tags] in your case) and hide the original field.  
The original field can still be updated by automations, but users see only the (read-only) formula field.

---

<div class="post-metadata">

**Author:** ![BertrandC](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/bertrandc/32/4828_2.png) [@BertrandC](https://community.fibery.io/u/BertrandC)\
**Post date:** [October 28, 2022, 2:12pm UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/36 "2022-10-28T14:12:36Z")

</div>

To whoever may be interesting, I’ve got inspired by @Matt_Blais (thanks for sharing your solution btw 🙏) to automatize a similar (but not exactly the same) mechanism (roadmap orientated).

Our setup is the following:

- We have 2 databases for tasks and studies
- For each Task/Study, we have a collection of Involved teams (e.g. which team is contributing to which Task/Study) which is updated depending on Task/Study assignee.s.
- Several Task & Study are part of an Internal Goal
- Several Internal Goal are constituting a Milestone

Our main challenge is that a team involved on a Task/Study may evolve, list of Task/Study linked to an Internal Goal may evolve and list of Internal Goal linked to a Milestone may evolve.  
Target is to get a unified field listing all Involved teams in each Milestone and Internal Goal.

We did implement the following solution to replace the `union()` feature without any human intervention:

1. in each Internal Goal, we have 2 Lookup fields  
1.1. Lookup of all Team.s from linked Task - field is hidden from card view  
1.2. Lookup of all Team.s from linked Study - field is hidden from card view
2. in each Internal Goal, we have a many-to-many relation field with the Team items
3. we have 4 automation rules allowing to update this many-to-many field (all running on the Internal Goal layer):  
3.1. when Task is linked to the Internal Goal (e.g. new Task created), link added in the` 2. many-to-many relation`, based on `1.1 Lookup field`  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/5/5e6db84ea524f5c2ffcb939c8d7125748b1daae9.png)  
3.2. when Study is linked to the Internal Goal (e.g. new Study created), link added in the `2. many-to-many relation`, based on `1.2 Lookup field`  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/d/d2798e7cc34a4934e9c9647e61dac60cda139ea7.png)  
3.3. when Team is unlinked from the `1.1 Lookup field` (e.g. when a Task is assign to someone from another team or deleted and no other Task are involving the Team), the 2. many-to-many relation is cleared and updated based on `1.1 & 1.2 Lookup fields`  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/9/913e120dd1bdf5f78ed5904017ab2aa09712d1ff.png)  
3.4 when Team is unlinked from the `1.2 Lookup field` (e.g. when a Study is assign to someone from another team or deleted and no other Study are involving the Team), the 2. many-to-many relation is cleared and updated based on `1.1 & 1.2 Lookup fields`  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/3/325f0982283960252071093703b53a7c03da3618.png)
4. add a Lookup field in the Milestone checking the `2. many-to-many relation` from all linked Internal Goal.

As per Chris suggestion right above, you can add a last step to transform the 2. many-to-many relation into a read-only field and hide the rewritable one.  
Checked so far: removing/reassigning/creating seem to work pretty fine 🤞.

Let me know if you need any further clarifications, I’ll be glad to share some screenshots/details if it can help.

@Chr1sG this workaround does not replace the `union()` feature need as I’m quite sure it won’t adapt to all setups/way of working 🙂

---

<div class="post-metadata">

**Author:** ![njyo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/njyo/32/923_2.png) [@njyo](https://community.fibery.io/u/njyo)\
**Post date:** [October 11, 2023, 8:16am UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/37 "2023-10-11T08:16:17Z")

</div>

Having Union() would be great!

As long as I can use Union() to ensure that a collection only contains each value once, then I don’t need a Unique() function before using Join().

Having Intersect() and Diff() feels like natural and quick additions when creating Union(). I mean it’d be like providing plus but no minus or multiply… 🙊

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [October 11, 2023, 11:12am UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/38 "2023-10-11T11:12:04Z")

</div>

> [@njyo](#):
>
> As long as I can use Union() to ensure that a collection only contains each value once, then I don’t need a Unique() function before using Join().

Fibery collections cannot contain the same entity twice, per definition, so if/when we introduce union, there will be no issue with duplicates.

---

<div class="post-metadata">

**Author:** ![njyo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/njyo/32/923_2.png) [@njyo](https://community.fibery.io/u/njyo)\
**Post date:** [October 11, 2023, 12:37pm UTC](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467/39 "2023-10-11T12:37:58Z")

</div>

I would assume this to happen on assignment, not sure how it would behave during processing “in memory” in a formula. If that’s baked in, then great!

[Previous page](https://community.fibery.io/t/how-to-union-two-list-fields-in-the-same-database/2467.md?page=1)
