# How can i get a distinct USERID from a table

**URL:** https://discuss.elastic.co/t/how-can-i-get-a-distinct-userid-from-a-table/221728
**Category:** Kibana
**Created:** [March 2, 2020, 4:24pm UTC](https://discuss.elastic.co/t/how-can-i-get-a-distinct-userid-from-a-table/221728 "2020-03-02T16:24:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![axedenim](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@axedenim](https://discuss.elastic.co/u/axedenim)
#### Post date: [March 2, 2020, 4:24pm UTC](https://discuss.elastic.co/t/how-can-i-get-a-distinct-userid-from-a-table/221728/1 "2020-03-02T16:24:28Z")

</div>

I have a SQL query for SELECT DISTINCT(USER\_ID) FROM TABLENAME

Need help to frame the query on Kibana for elastic search

---

<div class="post-metadata">

### Author: ![Aaron\_Caldwell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron_caldwell/32/45755_2.png) [@Aaron\_Caldwell](https://discuss.elastic.co/u/Aaron_Caldwell)
#### Post date: [March 2, 2020, 5:51pm UTC](https://discuss.elastic.co/t/how-can-i-get-a-distinct-userid-from-a-table/221728/2 "2020-03-02T17:51:51Z")

</div>

Hello,

I'm not certain Elasticsearch SQL supports the `distinct` syntax, but you should be able to accomplish this using a terms aggregation. Something like the following:

```auto
GET /<your index>/_search
{
  "size": 0,
  "aggs": {
    "distinct_userids": {
      "terms": {
        "field": "userid",
        "size": 1000
      }
    }
  }
}

```

Regards,  
Aaron

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [March 30, 2020, 5:51pm UTC](https://discuss.elastic.co/t/how-can-i-get-a-distinct-userid-from-a-table/221728/3 "2020-03-30T17:51:58Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
