public function Select::orderBy

Same name in this branch
  1. 8.x drupal/core/lib/Drupal/Core/Database/Query/Select.php \Drupal\Core\Database\Query\Select::orderBy()
  2. 8.x drupal/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php \Drupal\Core\Database\Driver\pgsql\Select::orderBy()

Orders the result set by a given field.

If called multiple times, the query will order by each specified field in the order this method is called.

If the query uses DISTINCT or GROUP BY conditions, fields or expressions that are used for the order must be selected to be compatible with some databases like PostgreSQL. The PostgreSQL driver can handle simple cases automatically but it is suggested to explicitly specify them. Additionally, when ordering on an alias, the alias must be added before orderBy() is called.

Parameters

$field: The field on which to order.

$direction: The direction to sort. Legal values are "ASC" and "DESC".

Return value

Drupal\Core\Database\Query\SelectInterface The called object.

Overrides SelectInterface::orderBy

2 calls to Select::orderBy()
Select::orderBy in drupal/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php
Overrides SelectQuery::orderBy().
Select::orderRandom in drupal/core/lib/Drupal/Core/Database/Query/Select.php
Orders the result set by a random value.
1 method overrides Select::orderBy()
Select::orderBy in drupal/core/lib/Drupal/Core/Database/Driver/pgsql/Select.php
Overrides SelectQuery::orderBy().

File

drupal/core/lib/Drupal/Core/Database/Query/Select.php, line 543
Definition of Drupal\Core\Database\Query\Select

Class

Select
Query builder for SELECT statements.

Namespace

Drupal\Core\Database\Query

Code

public function orderBy($field, $direction = 'ASC') {
  $this->order[$field] = $direction;
  return $this;
}