# Order ascending by uid

**URL:** <https://discuss.dgraph.io/t/order-ascending-by-uid/5798>\
**Category:** Dgraph\
**Created:** [January 10, 2020, 11:13am UTC](https://discuss.dgraph.io/t/order-ascending-by-uid/5798 "2020-01-10T11:13:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pablog](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pablog/32/2426_2.png) [@pablog](https://discuss.dgraph.io/u/pablog)\
**Post date:** [January 10, 2020, 11:13am UTC](https://discuss.dgraph.io/t/order-ascending-by-uid/5798/1 "2020-01-10T11:13:20Z")

</div>

Hello.

Is it possible to order the results of a query by uid?  
I’ve read somewhere in the documentation that lists like [uid] in dgraph are unsorted sets and by default they are ordered (descending) by uid. However if I try to order ascending the results I get

```auto
Message: : Cannot sort by unknown attribute uid

```

Is there any way to do it?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [January 10, 2020, 3:52pm UTC](https://discuss.dgraph.io/t/order-ascending-by-uid/5798/2 "2020-01-10T15:52:22Z")

</div>

> [@pablog](#):
>
> Is it possible to order the results of a query by uid?

As far as I can tell, all unordered or without order will be ordered by uid. But UID ordering isn’t sorting order friendly. Cuz it is randomly assigned.

From Docs:

> Note Without a sort order specified, the results are sorted by `uid` , which is assigned randomly. So the ordering, while deterministic, might not be what you expected. Source: [Get started with Dgraph](https://docs.dgraph.io/query-language/#pagination)

> Query Example: A movie in each genre that has over 30000 movies. Because there is no order specified on genres, the order will be by UID.

> [@pablog](#):
>
> by default they are ordered (descending) by uid.

That feels wrong. It is ascending by default.

> [@pablog](#):
>
> Is there any way to do it?

You can’t explicitly set uid as order param. By it is already ordered by uid.

Cheers.

---

<div class="post-metadata">

**Author:** ![pablog](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pablog/32/2426_2.png) [@pablog](https://discuss.dgraph.io/u/pablog)\
**Post date:** [January 10, 2020, 7:09pm UTC](https://discuss.dgraph.io/t/order-ascending-by-uid/5798/3 "2020-01-10T19:09:54Z")

</div>

As usual, thanks for your answer @MichelDiz
