Skip to main content

How to write this raw SQL query in Active Record Query Interface

Rails • Asked by W.M.

Here's the SQL:

select s.name, p.name, count(i.id) as count from items i
left join products p
on p.id = i.product_id
left join stores s
on s.id = i.store_id
group by p.id, s.id

Thank you.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.