开发者

Doctrine2 random query

开发者 https://www.devze.com 2023-03-13 15:01 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消