---
title: "Feature: #32051 - Extbase query expression builder for orderings"
manual: "TYPO3 Core Changelog"
version: "main"
permalink: "https://docs.typo3.org/permalink/changelog:feature-32051-1737628800"
source: "Changelog/14.2/Feature-32051-ExtbaseQueryExpressionBuilderForOrderings.rst"
typo3-version: "14.2"
typo3-major: 14
type: "feature"
issue: 32051
forge: "https://forge.typo3.org/issues/32051"
tags: ["PHP-API", "ext:extbase"]
rendered: "2026-09-20T18:31:11+00:00"
---

# Feature: #32051 - Extbase query expression builder for orderings {#feature-32051-1737628800}

See [forge#32051](https://forge.typo3.org/issues/32051)

## Description {#description}

Extbase queries now support SQL expressions in `ORDER BY`
clauses through a new fluent API. This enables results to be sorted using
functions such as `CONCAT`, `TRIM`, and `COALESCE`.

The following methods have been added to the
`\TYPO3\CMS\Extbase\Persistence\QueryInterface`:

-   `orderBy()` \- Sets a single ordering and replaces any existing
    orderings
-   `addOrderBy()` \- Adds an ordering to the existing orderings
-   `concat()` \- Creates a `CONCAT` expression
-   `trim()` \- Creates a `TRIM` expression
-   `coalesce()` \- Creates a `COALESCE` expression

### Examples {#examples}

Order by concatenated fields:

```php
$query = $this->myRepository->createQuery();
$query->orderBy(
    $query->concat('firstName', 'lastName'),
    QueryInterface::ORDER_ASCENDING
);
```

Order by a trimmed field:

```php
$query->orderBy(
    $query->trim('title'),
    QueryInterface::ORDER_DESCENDING
);
```

Order by the first non-null value (a fallback pattern):

```php
$query->orderBy(
    $query->coalesce('nickname', 'firstName'),
    QueryInterface::ORDER_ASCENDING
);
```

Chain multiple orderings:

```php
$query
    ->orderBy($query->concat('firstName', 'lastName'))
    ->addOrderBy('createdAt', QueryInterface::ORDER_DESCENDING);
```

Nest expressions:

```php
$query->orderBy(
    $query->concat(
        $query->trim('firstName'),
        $query->trim('lastName')
    )
);
```

### Backwards compatibility {#backwards-compatibility}

The existing `setOrderings()` method with its array syntax will continue to work:

```php
$query->setOrderings([
    'title' => QueryInterface::ORDER_ASCENDING,
    'date' => QueryInterface::ORDER_DESCENDING,
]);
```

## Impact {#impact}

Developers can now use SQL functions in Extbase query orderings without
resorting to raw SQL statements. This enables more flexible sorting logic
while maintaining the abstraction and security benefits of the Extbase
persistence layer.
