public function SelectQuery::orderBy

7.x select.inc public SelectQuery::orderBy($field, $direction = 'ASC')

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

SelectQueryInterface The called object.

Overrides SelectQueryInterface::orderBy

2 calls to SelectQuery::orderBy()
SelectQuery::orderRandom in drupal-7.x/includes/database/select.inc
Orders the result set by a random value.
SelectQuery_pgsql::orderBy in drupal-7.x/includes/database/pgsql/select.inc
Overrides SelectQuery::orderBy().
1 method overrides SelectQuery::orderBy()
SelectQuery_pgsql::orderBy in drupal-7.x/includes/database/pgsql/select.inc
Overrides SelectQuery::orderBy().

File

drupal-7.x/includes/database/select.inc, line 1386

Class

SelectQuery
Query builder for SELECT statements.

Code

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