> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cube.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Getting unique values for a field

> Recipe for powering filter dropdowns by querying distinct dimension values from Cube’s data APIs on a users-by-city example.

## Use case

We have a dashboard with information about the users, and we'd like to filter
them by city. To do so, we need to display all unique values for cities in the
dropdown. In the recipe below, we'll learn how to get unique values for
[dimensions](/reference/data-modeling/dimensions).

## Data modeling

To filter users by city, we need to define the appropriate dimension:

<CodeGroup>
  ```yaml title="YAML" theme={"dark"}
  cubes:
    - name: users
      sql_table: users

      dimensions:
        - name: city
          sql: city
          type: string

        - name: state
          sql: state
          type: string
  ```

  ```javascript title="JavaScript" theme={"dark"}
  cube(`users`, {
    sql_table: `users`,

    dimensions: {
      city: {
        sql: `city`,
        type: `string`
      },

      state: {
        sql: `state`,
        type: `string`
      }
    }
  })
  ```
</CodeGroup>

## Query

It is enough to include only a dimension in the query to get all unique values
of that dimension:

```json theme={"dark"}
{
  "dimensions": ["users.city"]
}
```

## Result

We got the unique values of the `city` dimension, and now we can use them in the
dropdown on the dashboard:

```json theme={"dark"}
[
  {
    "users.city": "Austin"
  },
  {
    "users.city": "Chicago"
  },
  {
    "users.city": "Los Angeles"
  },
  {
    "users.city": "Mountain View"
  }
]
```

## Choosing dimensions

In case we need to choose a dimension or render dropdowns for all dimensions, we
can fetch the list of dimensions for all cubes from the
[`/meta` endpoint](/reference/core-data-apis/rest-api/reference#base_path/v1/meta):

```bash theme={"dark"}
curl http://localhost:4000/cubejs-api/v1/meta
```

```json theme={"dark"}
{
  "cubes": [
    {
      "name": "users",
      "title": "Users",
      "measures": [],
      "dimensions": [
        {
          "name": "users.city",
          "title": "Users City",
          "type": "string",
          "shortTitle": "City",
          "suggestFilterValues": true
        },
        {
          "name": "users.state",
          "title": "Users State",
          "type": "string",
          "shortTitle": "State",
          "suggestFilterValues": true
        }
      ],
      "segments": []
    }
  ]
}
```

Then, we can iterate through dimension names and use any of them in a
[query](#query).

## Source code

Please feel free to check out the
[full source code](https://github.com/cube-js/cube/tree/master/examples/recipes/getting-unique-values-for-a-field)
or run it with the `docker-compose up` command. You'll see the result, including
queried data, in the console.
