# Multiple selection drop down

**URL:** <https://forum.inductiveautomation.com/t/multiple-selection-drop-down/99415>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 4, 2024, 12:22pm UTC](https://forum.inductiveautomation.com/t/multiple-selection-drop-down/99415 "2024-12-04T12:22:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [December 4, 2024, 12:22pm UTC](https://forum.inductiveautomation.com/t/multiple-selection-drop-down/99415/1 "2024-12-04T12:22:43Z")

</div>

Using mutiple selection drop downs to try and build a query where statement.

What is a good way to loop through the selected options and pull those selections out to build the query?

Say I have 5 options in the drop down and the user selects 2 of them.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [December 4, 2024, 12:35pm UTC](https://forum.inductiveautomation.com/t/multiple-selection-drop-down/99415/2 "2024-12-04T12:35:20Z")

</div>

Hello!

I used something like this for a onClick event on a button to filter a query based on multiselect dropdown.

```python
# Get reference to 'businessUnit' multiple dropdown filter
tab_container = self.getSibling("TabContainer")
business_units = [bu[3:] for bu in tab_container.custom.tableFilter] if tab_container.custom.tableFilter else ['DEFAULT_SITE']

# Construct SQL with placeholders
query = """
    SELECT *
    FROM WorkOrder WO
    WHERE WO.businessUnit IN ({businessUnits})
""".format(businessUnits=", ".join(["?" for _ in business_units]))

# Execute query
try:
    results = system.db.runPrepQuery(query, business_units, "DATABASE_NAME")
    if tab_container:
        tab_container.getChild("TablaOT").props.data = system.dataset.toDataSet(results)
    
  
    self.getSibling("textArea-1").props.text = "Query executed successfully and table data updated."
except Exception as e:

    self.getSibling("textArea-1").props.text = f"Error executing query: {e}"

```

hope it helps.

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [December 4, 2024, 5:52pm UTC](https://forum.inductiveautomation.com/t/multiple-selection-drop-down/99415/4 "2024-12-04T17:52:35Z")

</div>

Further information now that I'm awake more. Im lookint to have 3 or 4 mutilple selection drop down objects. The user will select possibly multiple from each then press a "Start" button.

It would then build a query based off the outputs selected

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 4, 2024, 6:32pm UTC](https://forum.inductiveautomation.com/t/multiple-selection-drop-down/99415/5 "2024-12-04T18:32:27Z")

</div>

You'll need to give more information.

1. How are the dropdown values related to the database columns?
2. Are you trying to create a query of the form,

```python
SELECT col1, col2, col3
FROM myTable
WHERE
    col1 IN (dd1[2], dd0[5], dd0[6])
    AND
    col2 IN (dd2[7])
    AND
    col3 IN (dd3[0], dd0[2], dd0[11])

```

where those `ddx[n]` values are determined by the dropdowns?

1. What is to happen if a dropdown has no selection?
2. Why do you need a "Start" button? You can let it update on every selection.

---

<div class="post-metadata">

**Author:** ![Eric\_Ervin](https://avatars.discourse-cdn.com/v4/letter/e/ecd19e/32.png) [@Eric\_Ervin](https://forum.inductiveautomation.com/u/Eric_Ervin)\
**Post date:** [December 4, 2024, 11:20pm UTC](https://forum.inductiveautomation.com/t/multiple-selection-drop-down/99415/6 "2024-12-04T23:20:23Z")

</div>

The overall result is to pull production data from multiple plant areas and combine.

First drop down would be forge where it is 4 lines. Id like to be all to select all or 1 or any number in between. 2nd drop down is Turning, it has 5 lines. Same concept being able to select any combination of lines to create the query for the database of part output.

If a selection is blank it should be ignored by the query builder.

The start button was just a way for me to focus my process thoughts currently. Its not a requirement.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 4, 2024, 11:37pm UTC](https://forum.inductiveautomation.com/t/multiple-selection-drop-down/99415/7 "2024-12-04T23:37:58Z")

</div>

You didn't adequately answer questions 1 and 2.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [December 5, 2024, 8:00am UTC](https://forum.inductiveautomation.com/t/multiple-selection-drop-down/99415/8 "2024-12-05T08:00:08Z")

</div>

Just a quick tip:  
`", ".join(["?" for _ in business_units])`

You don't need the square brackets here, `join` can work with a generator.
