# Hubdb complex queries using AND and OR logic combined

**URL:** <https://community.hubspot.com/t/hubdb-complex-queries-using-and-and-or-logic-combined/31349>\
**Category:** CMS Development\
**Tags:** hubdb\
**Created:** [February 5, 2021, 3:48pm UTC](https://community.hubspot.com/t/hubdb-complex-queries-using-and-and-or-logic-combined/31349 "2021-02-05T15:48:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CMcNamee](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cmcnamee/32/82797_2.png) [@CMcNamee](https://community.hubspot.com/u/CMcNamee)\
**Post date:** [February 5, 2021, 3:48pm UTC](https://community.hubspot.com/t/hubdb-complex-queries-using-and-and-or-logic-combined/31349/1 "2021-02-05T15:48:57Z")

</div>

Let’s say I have a table with columns: category, material, state, building type. And I want to use complex query logic by combining AND and OR, for example:

all rows where category=residential AND (material = clay OR material = asphalt) AND (state = IL) AND (building type = maintenence OR building type = storm)

How would I go about doing this with Hubl? Is this possible? I have looked through the hubdb documentation and also the api documentation and I didn’t find anything about complex logic.

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [February 5, 2021, 9:14pm UTC](https://community.hubspot.com/t/hubdb-complex-queries-using-and-and-or-logic-combined/31349/2 "2021-02-05T21:14:43Z")

</div>

Hey @CMcNamee

Welcome to the Community!

This is right up the alley of @alyssamwilie and @Gonzalo !

Maybe they can help out!

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [February 5, 2021, 11:06pm UTC](https://community.hubspot.com/t/hubdb-complex-queries-using-and-and-or-logic-combined/31349/3 "2021-02-05T23:06:27Z")

</div>

@CMcNamee If you’re using multiselect columns for the ones you want to do an OR query on you can use the \_\_in expression and a comma to separate the options you want to check against.

`{% set rows = hubdb_table_rows(XXXXXX, '&category __eq=residential&state=IL&material__ in=clay,asphalt&building_type__in=maintenence,storm') %}`
