# Ordering

When fetching multiple entries you can use the `orderBy` argument to define the order of the returned records.

When fetching multiple entries you can use the `orderBy` argument to define the order of the returned records.

You can order results by all [System Fields](https://hygraph.com/docs/api-reference/schema/system-fields), and any non-relational custom field you define in your model, either ascending, or descending.

## Order by types

| Input Type         | Description                              |
| ------------------ | ---------------------------------------- |
| `[fieldName]_ASC`  | Order results by `fieldName` ascending.  |
| `[fieldName]_DESC` | Order results by `fieldName` descending. |

  **ASC**

```graphql
{
  posts(orderBy: createdAt_ASC) {
    id
    createdAt
  }
}
```

  
  **DESC**

```graphql
{
  posts(orderBy: createdAt_DESC) {
    id
    createdAt
  }
}
```


**Warning:**
You can only use **one** `inputType` with `orderBy` to order results.

## Nested ordering

You can use the `orderBy` with [two-way references](https://hygraph.com/docs/api-reference/schema/field-types#two-way-references). 

[One-way references](https://hygraph.com/docs/api-reference/schema/field-types#one-way-references) and [union-type relations](https://hygraph.com/docs/api-reference/schema/field-types#union) are not supported.

For example, let's imagine our post has a `authors` relation. The same `orderBy` rules apply.

```graphql
{
  posts {
    id
    createdAt
    relatedPosts(orderBy: createdAt_DESC) {
      id
      createdAt
    }
  }
}
```
