Jump to:

5540 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » SQLQuery() and orderby = 'RAND()'

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1932 Views
  • Anatol
    126 Posts

    SQLQuery() and orderby = 'RAND()' Link to this post


    I want to get a random result from a quite specialised SQL query. I built the query simply using SQLQuery:

    $sqlQuery = new SQLQuery();
    $sqlQuery->select = array( ... etc ... );
    $sqlQuery->from = array( ... etc ...);
    ... etc ...
    $sqlQuery->orderBy = 'RAND()';

    Works all perfectly except $sql->orderBy = 'RAND()';

    If I order by a specific field it's fine, but ORDER BY RAND() simply gets stripped out of the query when I run


    Do I do anything wrong or is RAND() simply not supported as an orderby value? If it's not supported may I suggest to include this in a future version of Silverstripe?


Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.