Zend Framework - applying order by on a nested query
- by Gublooo
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()');