# MySQL Select Value and Decrement

**URL:** <https://forum.inductiveautomation.com/t/mysql-select-value-and-decrement/19325>\
**Category:** Ignition\
**Created:** [August 20, 2018, 3:01pm UTC](https://forum.inductiveautomation.com/t/mysql-select-value-and-decrement/19325 "2018-08-20T15:01:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 20, 2018, 3:01pm UTC](https://forum.inductiveautomation.com/t/mysql-select-value-and-decrement/19325/1 "2018-08-20T15:01:15Z")

</div>

I have a label that runs a query on property change and shows a part’s max qty for a certain product. Below this I have a drop down menu for order quantity, and I don’t want a quantity to be ordered that is more than what the product takes. So if the query returns a max qty of 4, then the drop down menu should have a dataset of [0,1,2,3,4]. Any ideas on how to return a dataset from a value selected by query that is decremented down to zero? thanks

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [August 20, 2018, 3:43pm UTC](https://forum.inductiveautomation.com/t/mysql-select-value-and-decrement/19325/2 "2018-08-20T15:43:43Z")

</div>

```auto
maxQuantity = 4 # replace with the result of your query
dropdown = event.source.parent.getComponent('ddlQuantity') # or whatever your dropdown is called
quantities = [[x] for x in range(maxQuantity+1)]
dropdown.data = system.dataset.toDataSet(["Quantity"], quantities)

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [August 20, 2018, 3:56pm UTC](https://forum.inductiveautomation.com/t/mysql-select-value-and-decrement/19325/3 "2018-08-20T15:56:51Z")

</div>

Ah, I didn’t even think about doing it in scripting after running the query. I was trying to do it in the query itself. Cool thanks!
