【发布时间】:2010-09-30 21:07:17
【问题描述】:
因为我使用 Rails,所以我对 sql 已经生锈了,因为我很少在 rails 中使用它。 我有两个相关的表: cmets 1:m comment_views
我想找到comment_views.viewed 为假的所有cmets。问题是,对于某些 cmets,comment_views 中还没有相关记录。
目前为止
select comments.id
from comments
left join comment_views
on comments.id = comment_views.comment_id
where comment_views.viewed != "t"
group by type_id, object_id
order by comments.created_at desc
但如上所述,当 comment_views 中没有记录时,它不会返回 cmets。
【问题讨论】:
标签: sql ruby-on-rails join find-by-sql