DDC-950: Selecting entities in random order #1180

Closed
opened 2026-01-22 13:04:53 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 26, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user enumag:

I need some way to select a random row from a table. There was something like "ORDER BY RAND()" in SQL but I can't really find anything like that for Doctrine.

Originally created by @doctrinebot on GitHub (Dec 26, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user enumag: I need some way to select a random row from a table. There was something like "ORDER BY RAND()" in SQL but I can't really find anything like that for Doctrine.
admin closed this issue 2026-01-22 13:04:55 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 27, 2010):

Comment created by @beberlei:

Doctrine allows you to execute SQL and hydrate objects from that using the Native Query API as described in the documentation.

@doctrinebot commented on GitHub (Dec 27, 2010): Comment created by @beberlei: Doctrine allows you to execute SQL and hydrate objects from that using the Native Query API as described in the documentation.
Author
Owner

@doctrinebot commented on GitHub (Dec 27, 2010):

Issue was closed with resolution "Won't Fix"

@doctrinebot commented on GitHub (Dec 27, 2010): Issue was closed with resolution "Won't Fix"
Author
Owner

@doctrinebot commented on GitHub (Jun 10, 2011):

Comment created by darkangel:

I need this as well ... why can't we do something like:

$qb->orderBy('RAND()');

Or maybe something at a lower level, like:

$qb->add('orderBy', new Expr\Func('RAND', array()));

?

@doctrinebot commented on GitHub (Jun 10, 2011): Comment created by darkangel: I need this as well ... why can't we do something like: ``` $qb->orderBy('RAND()'); ``` Or maybe something at a lower level, like: ``` $qb->add('orderBy', new Expr\Func('RAND', array())); ``` ?
Author
Owner

@doctrinebot commented on GitHub (May 3, 2012):

Comment created by petersvp:

I need this as well! ORDER BY RAND() or something like this is a MUST HAVE for Doctrine! I do NOT want to fetch ALL then Hydrate ALL to select some rows, nor I want to do 2 queries in a row! Also, last one method actually can return 2 SAME records....

Hope I see this soon. I'm using Symfony 2

@doctrinebot commented on GitHub (May 3, 2012): Comment created by petersvp: I need this as well! ORDER BY RAND() or something like this is a MUST HAVE for Doctrine! I do NOT want to fetch ALL then Hydrate ALL to select some rows, nor I want to do 2 queries in a row! Also, last one method actually can return 2 SAME records.... Hope I see this soon. I'm using Symfony 2
Author
Owner

@doctrinebot commented on GitHub (Jan 29, 2014):

Comment created by daslicht:

+1 Please add this feature

@doctrinebot commented on GitHub (Jan 29, 2014): Comment created by daslicht: +1 Please add this feature
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1180