Zend Framework - applying order by on a nested query
        Posted  
        
            by Gublooo
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Gublooo
        
        
        
        Published on 2010-03-24T16:44:27Z
        Indexed on 
            2010/03/29
            9:43 UTC
        
        
        Read the original article
        Hit count: 415
        
Hey guys
This might be a very simple thing. Check out the normal sql query below
(select * from shopping order by shopping_id desc limit 5) order by RAND()
This query runs successfully in mysql - not sure if this is the right way of doing it - but it works. It gets the last 5 ids from shopping table and randomly orders them everytime
I want to achieve this in Zend. I'm not sure how to execute the first part and then apply the RAND clause to the results - what I have below does not do that.
$select = $this->select()       
           ->from(array('sh'=>'shopping'))
           ->order('shopping_id desc')
           ->limit(5)    
           ->order('RAND()');
        © Stack Overflow or respective owner