我在我的网站上有一个精选部分,其中包含三种类型的精选文章:正常,大和小。目前,我取了三种类型的三个单独的查询,像这样:Rails SQL查询优化
@featured_big_first = Post.visible.where(pinged: 1).where('overlay_type =?', :big).limit(1)
@featured_big_first = Post.visible.where(pinged: 1).where('overlay_type =?', :small).limit(1)
@featured_big_first = Post.visible.where(pinged: 1).where('overlay_type =?', :normal).limit(5)
基本上我寻找一个查询,将在这三个结合,一个取1大,1小,5例正常帖子。
感谢您的建议,我会执行它。在接受你的答案之前,我会等一下,b/c我相信这可以通过使用'UNION'的自定义sql查询来实现。 – zevstatiev
当然是的,即使我想学习一件新的东西:) – Salil