W3cubDocs

/Drupal 8

public function SelectExtender::orderRandom

public SelectExtender::orderRandom()

Orders the result set by a random value.

This may be stacked with other orderBy() calls. If so, the query will order by each specified field, including this one, in the order called. Although this method may be called multiple times on the same query, doing so is not particularly useful.

Note: The method used by most drivers may not scale to very large result sets. If you need to work with extremely large data sets, you may create your own database driver by subclassing off of an existing driver and implementing your own randomization mechanism. See

http://jan.kneschke.de/projects/mysql/order-by-rand/

for an example of such an alternate sorting mechanism.

Return value

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

Overrides SelectInterface::orderRandom

File

core/lib/Drupal/Core/Database/Query/SelectExtender.php, line 396

Class

SelectExtender
The base extender class for Select queries.

Namespace

Drupal\Core\Database\Query

Code

public function orderRandom() {
  $this->query->orderRandom();
  return $this;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Query!SelectExtender.php/function/SelectExtender::orderRandom/8.1.x