# List A contains at least 1 of List B

**URL:** <https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459>\
**Category:** Questions\
**Created:** [December 23, 2021, 12:02pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459 "2021-12-23T12:02:00Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![NigelG](https://avatars.discourse-cdn.com/v4/letter/n/ea5d25/32.png) [@NigelG](https://forum.bubble.io/u/NigelG)\
**Post date:** [December 23, 2021, 12:02pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/1 "2021-12-23T12:02:00Z")

</div>

So, I had a question from a new Bubbler who was trying to do a filter by Tags.

The database thing has a list of tags (they are option sets, but don’t think that is relevant) and the page has a multidropdown of tags.

So the search filter can be done by an Advanced Filter…

this thing’s list of tags : intersects with multidropdowns value : count \> 0

The question was “is that really the easiest way” ?

“Contains” doesn’t work because that checks for a single tag.

Have been doing it with count\>0 on interspect for years. But wondered if something had come along recently (for each?) that would make it simpler?

---

<div class="post-metadata">

**Author:** ![lottemint.md](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/lottemint.md/32/26549_2.png) [@lottemint.md](https://forum.bubble.io/u/lottemint.md)\
**Post date:** [December 23, 2021, 12:06pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/2 "2021-12-23T12:06:05Z")

</div>

That’s a sensitive subject. I wish to have that option as a constraint in the searches.

---

<div class="post-metadata">

**Author:** ![TipLister](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/tiplister/32/150194_2.png) [@TipLister](https://forum.bubble.io/u/TipLister)\
**Post date:** [December 23, 2021, 12:45pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/3 "2021-12-23T12:45:18Z")

</div>

I convert the list of tags into one text field  
and do text contains eg inputs values (or multidropdown triggered text state)

---

<div class="post-metadata">

**Author:** ![ed727](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/ed727/32/71942_2.png) [@ed727](https://forum.bubble.io/u/ed727)\
**Post date:** [December 23, 2021, 3:57pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/4 "2021-12-23T15:57:30Z")

</div>

> [@NigelG](#):
>
> The question was “is that really the easiest way” ?

To me, it’s the easiest way, but not the most scalable way. Joining tables are more scalable since you can search them server side. But they bring their own set of issues to work through.

> [@lottemint.md](#):
>
> I wish to have that option as a constraint in the searches.

100% agree. I hope Bubble’s development plans involve enabling more search functionality server side.

> [@TipLister](#):
>
> I convert the list of tags into one text field  
> and do text contains eg inputs values (or multidropdown triggered text state)

Interesting… how do you handle a situation where one tag’s word is within another tag? If you have tags for “Dog” and “Dog Days” and “Bad Dog”, would selecting “Dog” return all of them, even though I just want “Dog”?

---

<div class="post-metadata">

**Author:** ![lottemint.md](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/lottemint.md/32/26549_2.png) [@lottemint.md](https://forum.bubble.io/u/lottemint.md)\
**Post date:** [December 23, 2021, 4:32pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/5 "2021-12-23T16:32:56Z")

</div>

> [@ed727](#):
>
> Interesting… how do you handle a situation where one tag’s word is within another tag? If you have tags for “Dog” and “Dog Days” and “Bad Dog”, would selecting “Dog” return all of them, even though I just want “Dog”?

Here, the best way to store tags in a separate table, I mean, as things - and then you can create a text field that should hold the selected tags with a space separator.

For instance, tables:

- Tag  
name | text
- Item  
Tags | List of Tag  
tags\_string | text

Tags:  
Dog - id\_1  
Dog Days - id\_2  
Bad Dog - id\_3

Item A:  
tags\_string - id\_1 id\_2 id\_3

Item B:  
tags\_string - id\_1 id\_2

Item C:  
tags\_string - id\_1

Now, you can use the following search:  
`Do search for Items where "tags_string" contains keyword(s) "selected_tags_source's unique_id join with ' ' (space)"`

So, if a user selects `Dog - id_1`, the system shows `Item A, Item B, Item C`  
So, if a user selects `Dog Days - id_2`, the system shows `Item B, Item A`  
So, if a user selects `Dog Days - id_2 and Dog - id_1`, the system shows `Item B, Item A`

* * *

The thing that I was trying achieve:  
If a user selects `Dog Days - id_2 and Bad Dog - id_3`, the system should show `Item B, Item C`

---

<div class="post-metadata">

**Author:** ![TipLister](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/tiplister/32/150194_2.png) [@TipLister](https://forum.bubble.io/u/TipLister)\
**Post date:** [December 23, 2021, 4:53pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/6 "2021-12-23T16:53:01Z")

</div>

how i handle it specifically is that each thing also has a list of categories…  
you click categories to add them to selection  
so it looks for things whose search text contains input searchs text + whose list of categories contains selected category/categories.

probably above approach is even more elegant as your initial datatype is less crowded due to not having a list of categories in it.  
well done @lottemint.md

---

<div class="post-metadata">

**Author:** ![ed727](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/ed727/32/71942_2.png) [@ed727](https://forum.bubble.io/u/ed727)\
**Post date:** [December 23, 2021, 5:04pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/7 "2021-12-23T17:04:16Z")

</div>

@lottemint.md and @TipLister thank you for the approaches!

Given how “contains keywords” works, I assume this approach only works in situations where all selected tags (vs. just one) must be in a thing’s list of tags for the thing to be returned.

---

<div class="post-metadata">

**Author:** ![sudsy](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sudsy/32/114637_2.png) [@sudsy](https://forum.bubble.io/u/sudsy)\
**Post date:** [December 25, 2021, 11:52pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/8 "2021-12-25T23:52:37Z")

</div>

I examined your response more closely, @lottemint.md, and I have a few questions…

> [@lottemint.md](#):
>
> Tags:  
> Dog - id\_1  
> Dog Days - id\_2  
> Bad Dog - id\_3
> 
> Item A:  
> tags\_string - id\_1 id\_2 id\_3
> 
> Item B:  
> tags\_string - id\_1 id\_2
> 
> Item C:  
> tags\_string - id\_1

> [@lottemint.md](#):
>
> So, if a user selects `Dog - id_1`, the system shows `Item A, Item B, Item C`

Makes sense.

> [@lottemint.md](#):
>
> So, if a user selects `Dog Days - id_2`, the system shows `Item B, Item C`

I don’t understand. Why would `Item C` be shown? It does not contain `id_2`. 😕

> [@lottemint.md](#):
>
> So, if a user selects `Dog Days - id_2 and Dog - id_1`, the system shows `Item B, Item C`

Why would `Item C` be shown if it does not contain `id_2`? 😕

> [@lottemint.md](#):
>
> The thing that I was trying achieve:  
> If a user selects `Dog Days - id_2 and Bad Dog - id_3`, the system should show `Item B, Item C`

`Item C` contains neither `id_2` nor `id_3`. Why would it be shown? 😕

Thanks for the clarification.

-Steve

---

<div class="post-metadata">

**Author:** ![sudsy](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sudsy/32/114637_2.png) [@sudsy](https://forum.bubble.io/u/sudsy)\
**Post date:** [December 26, 2021, 4:11am UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/9 "2021-12-26T04:11:21Z")

</div>

> [@ed727](#):
>
> I assume this approach only works in situations where all selected tags (vs. just one) must be in a thing’s list of tags

I find it helpful to think of the desired behavior from the end user’s perspective. Typically, the end user will want to do one of the following in a given search…

- Find items which contain _all_ of the selected tags
- Find items which contain _any_ of the selected tags

(A single selected tag would return the same result for either.)

~~If I understand correctly, the approaches described in this thread thus far seem to address the latter scenario. @NigelG’s approach does it client-side, whereas @lottemint.md’s approach does it server-side (at least I think that’s the intent - I’m awaiting clarification).~~

The above was incorrect. In fact, @NigelG’s client-side approach addresses the latter scenario (show items which contain _any_ of the selected tags), whereas @lottemint.md’s server-side approach addresses the first scenario (show items which contain _all_ of the selected tags).

It would be really nice if there was a simple way to accommodate each of the above scenarios server-side. Why can’t it be as simple as `contains all of list` and `contains any of list` operators?

-Steve

---

<div class="post-metadata">

**Author:** ![lottemint.md](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/lottemint.md/32/26549_2.png) [@lottemint.md](https://forum.bubble.io/u/lottemint.md)\
**Post date:** [December 26, 2021, 7:13pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/10 "2021-12-26T19:13:26Z")

</div>

> [@sudsy](#):
>
> `Item C` contains neither `id_2` nor `id_3`. Why would it be shown? 😕

Sorry for the confusion. I’ve updated my comment. 😅

---

<div class="post-metadata">

**Author:** ![lottemint.md](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/lottemint.md/32/26549_2.png) [@lottemint.md](https://forum.bubble.io/u/lottemint.md)\
**Post date:** [December 26, 2021, 7:28pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/11 "2021-12-26T19:28:29Z")

</div>

I’ve built a quick demo:

[https://s3.amazonaws.com/appforest\_uf/f1640546934428x359779988897003900/Screen%20Recording%202021-12-26%20at%2021.25.40.mov](https://s3.amazonaws.com/appforest_uf/f1640546934428x359779988897003900/Screen%20Recording%202021-12-26%20at%2021.25.40.mov)

Preview:  
username  
password  
[https://just4tests8.bubbleapps.io/version-test/tags](https://just4tests8.bubbleapps.io/version-test/tags)

Editor:

> **[Bubble Editor - Just4tests8](https://bubble.io/page?type=page&name=tags&id=just4tests8&tab=tabs-1)**
>
> Build stuff without code and launch a startup without a tech-cofounder! Bubble is a visual programing language. Instead of typing code, use a visual editor to build applications.

---

<div class="post-metadata">

**Author:** ![sudsy](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sudsy/32/114637_2.png) [@sudsy](https://forum.bubble.io/u/sudsy)\
**Post date:** [December 26, 2021, 8:08pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/12 "2021-12-26T20:08:35Z")

</div>

> [@lottemint.md](#):
>
> I’ve updated my comment. 😅

Thanks much! I see now that your approach is showing only items which have _all_ of the selected tags - not _any_ of the selected tags.

However, I think the last example in your post is incorrect…

> [@lottemint.md](#):
>
> The thing that I was trying achieve:  
> If a user selects `Dog Days - id_2 and Bad Dog - id_3`, the system should show `Item B, Item C`

I believe that would show only `Item A` as depicted in your vid.

> [@ed727](#):
>
> I assume this approach only works in situations where all selected tags (vs. just one) must be in a thing’s list of tags

That indeed appears to be the case. I will amend my other comment to reflect this and avoid further confusion.

-Steve

---

<div class="post-metadata">

**Author:** ![lottemint.md](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/lottemint.md/32/26549_2.png) [@lottemint.md](https://forum.bubble.io/u/lottemint.md)\
**Post date:** [December 26, 2021, 8:16pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/13 "2021-12-26T20:16:10Z")

</div>

![image](https://us1.discourse-cdn.com/bubble/original/3X/d/3/d3e15bc3b712f610e0338200c89cc1f535ab38f4.png)  
Here, I mean that it was something that I was trying to achieve, but without any luck (making it work on the server-side).

---

<div class="post-metadata">

**Author:** ![sudsy](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sudsy/32/114637_2.png) [@sudsy](https://forum.bubble.io/u/sudsy)\
**Post date:** [December 26, 2021, 8:19pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/14 "2021-12-26T20:19:00Z")

</div>

> [@TipLister](#):
>
> probably above approach is even more elegant as your initial datatype is less crowded due to not having a list of categories in it.

Unless I’m missing something, I think you’d want _both_ a list _and_ a “tag string”, so the data type would actually be heavier (although not by much). Otherwise, it would be a challenge to add/remove tags, whereas it’s trivial to regenerate the delimited tag string from the list when tags are added or removed.

-Steve

---

<div class="post-metadata">

**Author:** ![sudsy](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sudsy/32/114637_2.png) [@sudsy](https://forum.bubble.io/u/sudsy)\
**Post date:** [December 26, 2021, 8:27pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/15 "2021-12-26T20:27:43Z")

</div>

> [@lottemint.md](#):
>
> I mean that it was something that I was trying to achieve, but without any luck

Ah, ok. Got it! Thanks for taking the time to clarify.

FWIW, if anyone stumbling upon this thread feels (like I do) that this could (and should) be a whole lot easier in a no-code environment like Bubble, please take a moment to upvote [my feature suggestion in the Ideaboard](https://bubble.io/ideaboard).

You’ll have to search for “server-side constraints” to find it, as there’s apparently no way to link directly to an item in the Ideaboard. 😐

-Steve

---

<div class="post-metadata">

**Author:** ![shemeka](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@shemeka](https://forum.bubble.io/u/shemeka)\
**Post date:** [December 30, 2022, 10:52pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/16 "2022-12-30T22:52:46Z")

</div>

Upvoted. For those looking for it, I believe the idea is titled: Search constraint “contains list” server-side

---

<div class="post-metadata">

**Author:** ![bamapt](https://avatars.discourse-cdn.com/v4/letter/b/6bbea6/32.png) [@bamapt](https://forum.bubble.io/u/bamapt)\
**Post date:** [September 26, 2023, 7:18pm UTC](https://forum.bubble.io/t/list-a-contains-at-least-1-of-list-b/183459/17 "2023-09-26T19:18:50Z")

</div>

And here’s the direct link: [https://bubble.io/ideaboard?idea=1690442630636x884503575352836100](https://bubble.io/ideaboard?idea=1690442630636x884503575352836100)

Do upvote, ye bubblers, so we don’t have to create unnecessary data types and jump through hoops to do basic things such as complex server side searches!
