# Multi dropdown into SQL query. How to display array?

**URL:** <https://forum.inductiveautomation.com/t/multi-dropdown-into-sql-query-how-to-display-array/88783>\
**Category:** Maker\
**Tags:** ignition81, perspective\
**Created:** [April 13, 2024, 8:55pm UTC](https://forum.inductiveautomation.com/t/multi-dropdown-into-sql-query-how-to-display-array/88783 "2024-04-13T20:55:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [April 13, 2024, 8:55pm UTC](https://forum.inductiveautomation.com/t/multi-dropdown-into-sql-query-how-to-display-array/88783/1 "2024-04-13T20:55:29Z")

</div>

Hi there,

I'm trying to input a multi-dropdown (string) into SQL query, and display it in a table in Ignition.

The result looks like this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/6/d62a171fa9d13c97c7cbc4af41ad034c6d506f70.png)

And in igntion on the dropdown it looks like this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/f/4f9862fe9db845a285eca687da255073fdab7ab4.png)

Is there a smart way for how to display this nicely in the table? Do I need to concat the whole array, or is there a more elegant way?

---

<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:** [April 13, 2024, 9:32pm UTC](https://forum.inductiveautomation.com/t/multi-dropdown-into-sql-query-how-to-display-array/88783/2 "2024-04-13T21:32:17Z")

</div>

The dropdown should look like this:  
 ![Ole and Melhus dropdown](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/0/90f2e2a9257cccd07cd9407bdf68a4770a5c0d5f.png)

And the options should look like this:

```auto
[
  {
    "isDisabled": false,
    "label": "Ole",
    "value": 35
  },
  {
    "isDisabled": false,
    "label": "Melhus",
    "value": 72
  }
]

```

(I've given the employee number as 'value'. You could just repeat the names there.)

- You pass the dropdown's `value` property to the SQL query.
- You bind the table's data property to the SQL query.

> Is there a smart way for how to display this nicely in the table?

You don't display the dropdown in the table unless you are trying to use a dropdown to **edit** a table. Please clarify.

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [April 13, 2024, 10:37pm UTC](https://forum.inductiveautomation.com/t/multi-dropdown-into-sql-query-how-to-display-array/88783/3 "2024-04-13T22:37:53Z")

</div>

I am using multiple choise dropdown, and if i select multiple names, the output is an array of names. I then want to write the values to sql, then display the values in a table.

I can concat all vales of array like this «Ole, Melhus, Robert», but I was hoping for a more elegant solution 😁

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 13, 2024, 10:40pm UTC](https://forum.inductiveautomation.com/t/multi-dropdown-into-sql-query-how-to-display-array/88783/4 "2024-04-13T22:40:33Z")

</div>

Vanilla JDBC doesn't understand database columns that hold arrays. The JDBC drivers that do are brand-specific extensions. Ignition uses vanilla JDBC.

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [April 14, 2024, 9:41am UTC](https://forum.inductiveautomation.com/t/multi-dropdown-into-sql-query-how-to-display-array/88783/5 "2024-04-14T09:41:14Z")

</div>

Allright, so I guess I need to concat the string?

Not sure how to do this efficiently though... This is not the best way 😛  
concat(concat(concat({this.props.value}[0],", "),{this.props.value}[1]),", ")

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 14, 2024, 2:23pm UTC](https://forum.inductiveautomation.com/t/multi-dropdown-into-sql-query-how-to-display-array/88783/6 "2024-04-14T14:23:29Z")

</div>

Jython doesn't have a concat() function. Just use `+` to concatenate strings. Or, perhaps, use `','.join([some list])` to make a comma-delimited string of keywords.

---

<div class="post-metadata">

**Author:** ![Vidar\_Hetlelid](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vidar\_Hetlelid](https://forum.inductiveautomation.com/u/Vidar_Hetlelid)\
**Post date:** [April 14, 2024, 3:34pm UTC](https://forum.inductiveautomation.com/t/multi-dropdown-into-sql-query-how-to-display-array/88783/7 "2024-04-14T15:34:44Z")

</div>

Thanks, I didn't know i could concat using only +. This is the best I can do, which works in order to concat the values.

```auto
case(
    len({this.props.value}),      
    0,	"Alle",
    1,	{this.props.value}[0],
    2, {this.props.value}[0] + ", " + {this.props.value}[1],
    3, {this.props.value}[0] + ", " + {this.props.value}[1] + ", " + {this.props.value}[2],
  	4, {this.props.value}[0] + ", " + {this.props.value}[1] + ", " + {this.props.value}[2] + ", " + {this.props.value}[3],
	5, {this.props.value}[0] + ", " + {this.props.value}[1] + ", " + {this.props.value}[2] + ", " + {this.props.value}[3] + ", " + {this.props.value}[4],
 	6, {this.props.value}[0] + ", " + {this.props.value}[1] + ", " + {this.props.value}[2] + ", " + {this.props.value}[3] + ", " + {this.props.value}[4] + ", " + {this.props.value}[5],
  	7, {this.props.value}[0] + ", " + {this.props.value}[1] + ", " + {this.props.value}[2] + ", " + {this.props.value}[3] + ", " + {this.props.value}[4] + ", " + {this.props.value}[5] + ", " + {this.props.value}[6],
 	8, {this.props.value}[0] + ", " + {this.props.value}[1] + ", " + {this.props.value}[2] + ", " + {this.props.value}[3] + ", " + {this.props.value}[4] + ", " + {this.props.value}[5] + ", " + {this.props.value}[6] + ", " + {this.props.value}[7],
    "Alle" 
)

```

Problem is that even if i can write a string of names seperated by commas, the problem returns when i want to edit the table. When I click on a row, all editable cell values gets filled back into the dropdown, which don't support a string.... Hoping anyone can help me make this possible 🙂

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/f/ff414bb92f533decba1123af7b5fbea7408d3c66.png)

Maybe this must be done on the MySQL side? Maybe write all names into different columns, then concating all into 1 column when displaying the table? This was a tricky one 😕

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 14, 2024, 4:22pm UTC](https://forum.inductiveautomation.com/t/multi-dropdown-into-sql-query-how-to-display-array/88783/8 "2024-04-14T16:22:44Z")

</div>

Oy!

The canonical way to do this sort of many-to-many relationship is additional DB tables, for the choice options and for the connections between subjects and choices. Assembled in results via LEFT JOIN operations.

Typically **not** editable within a table of subjects, but displayable there using your SQL DB's `group_concat()` function while grouping by subject.

To edit, typically a side view or popup would present the multi-select input and perform the appropriate inserts/deletes upon the "connections" table.

You will certainly want to get comfortable using jython scripts--expressions are not good tools to provide parameters to insert/update queries.
