# pulling unique values from table into select

**URL:** <https://community.hubspot.com/t/pulling-unique-values-from-table-into-select/3930>\
**Category:** CMS Development\
**Created:** [November 16, 2017, 6:21pm UTC](https://community.hubspot.com/t/pulling-unique-values-from-table-into-select/3930 "2017-11-16T18:21:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpaullewer](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jpaullewer/32/61905_2.png) [@jpaullewer](https://community.hubspot.com/u/jpaullewer)\
**Post date:** [November 16, 2017, 6:21pm UTC](https://community.hubspot.com/t/pulling-unique-values-from-table-into-select/3930/1 "2017-11-16T18:21:53Z")

</div>

I need to pull a set of unique values from a particular table column. Specifically, I want to pull a distinct list of states and populate a select list. I have the following:

\<form id=“form\_id” method=“get”\>  
\<select name=“state” form=“form\_id” onChange=“form1.submit()”\>  
\<option value=“Select a State”\>Select a State\</option\>  
{% set rows = hubdb\_table\_rows(######, ‘&orderBy=state’) %}  
{% set names = rows|map(attribute=‘state’) %}  
{% for row in names %}  
{% if names == request.query\_dict.state %}  
\<option selected=“selected” value=“{{ row }}”\>{{ row }}\</option\>  
{% else %}  
\<option value=“{{ row }}”\>{{ row }}\</option\>  
{% endif %}  
{% endfor %}  
\</select\>  
\</form\>

It does just as it should in pulling all of the states and ordering them in a select object on a form. I could create a state table, however we don’t have business in every state and I want to only pull states where we have business. Is there a way to add “distinct” or “unique” to the hubdb\_table\_rows or possibly to the rows|map(attribute=‘state’) syntax that will do that?

Thanks.

---

<div class="post-metadata">

**Author:** ![TRooInbound](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/trooinbound/32/89545_2.png) [@TRooInbound](https://community.hubspot.com/u/TRooInbound)\
**Post date:** [November 17, 2017, 6:54am UTC](https://community.hubspot.com/t/pulling-unique-values-from-table-into-select/3930/2 "2017-11-17T06:54:59Z")

</div>

Hi @jpaullewer,

for selecting unique/distinct values of column from the table you need to call **hubdb\_table\_column(######, ‘state’).options** it will fetch your required data.

Below is your code with some modification to fetch unique or distnict value of state from the table.

```auto
<form id="form_id" method="get">
 <select name="state" form="form_id" onChange="form1.submit()">
 <option value="Select a State">Select a State</option>
 {% set stateValues = hubdb_table_column(######, 'state').options %}
 {% for row in stateValues %}
 {% if row.id == request.query_dict.state %}
 <option selected="selected" value="{{ row.id }}">{{ row.name }}</option>
 {% else %}
 <option value="{{ row.id }}">{{ row.name }}</option>
 {% endif %}
 {% endfor %}
 </select>
</form>

```

We hope it will work for you.

| ![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/1/71232bb65bd029237c40010174d30ea2bb57cbd6.png) | Did my post help answer your query? Help the Community by **marking it as a solution**. |  
| — | — |

**TRooInbound Team**

more help please visit at [www.trooinbound.com](https://trooinbound.com/) or email at [hello@trooinbound.com](mailto:hello@trooinbound.com)

---

<div class="post-metadata">

**Author:** ![jpaullewer](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jpaullewer/32/61905_2.png) [@jpaullewer](https://community.hubspot.com/u/jpaullewer)\
**Post date:** [November 17, 2017, 2:39pm UTC](https://community.hubspot.com/t/pulling-unique-values-from-table-into-select/3930/3 "2017-11-17T14:39:57Z")

</div>

Thank you. This solution only works if you set a column as a “select” type. I was trying to do this as a regular text column. I changed it to a select column and this solution does work. Thank you.
