Sam Wilson's Website

By .

Oh, maybe it's not possible!

https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/faq.html#can-i-sort-by-a-function-for-example-order-by-rand-in-dql

Can I sort by a function (for example ORDER BY RAND()) in DQL? No, it is not supported to sort by function in DQL. If you need this functionality you should either use a native-query or come up with another solution. As a side note: Sorting with ORDER BY RAND() is painfully slow starting with 1000 rows.

Tags: ·