I want to fetch 2 rows from my datab开发者_开发百科ase randomly with doctrine2, and I can't manage to do it. I figured out that there is no possibility to do it easily with RAND(), but then which is the best solution?
And from the table I want to select rows which are for example for sale, I mark it with 1 in is_sale, so because of this I couldn't do it with simple offset.
Thanks
When asking this question on Twitter just now, I got pointed to this post about selecting random records. This guy makes a very valid point on the performance of using RAND(). I guess it's better to generate the random id's in the application, then select those records using Doctrine.
精彩评论