# Multiple tables query

**URL:** <https://www.ruby-forum.com/t/multiple-tables-query/116682>\
**Category:** Rails\
**Created:** [October 8, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/multiple-tables-query/116682 "2007-10-08T18:42:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![niky81](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/51bf81/32.png) [@niky81](https://www.ruby-forum.com/u/niky81)\
**Post date:** [October 8, 2007, 6:42pm UTC](https://www.ruby-forum.com/t/multiple-tables-query/116682/1 "2007-10-08T18:42:38Z")

</div>

HI, I’ve read the basic books about ROR and even skimmed the recipes  
book but can’t find a standard path for my problem.  
I’ve to show data that due to relationships is going to take more  
tables, not one or two but 6/7 and even 13 in some cases. Now in other  
languages I usually write a quite long SQL statement and I get what I  
want. But with Rails? Should I work on the model? Should I create a view  
and then a class associated with it? Should I write the same old SQL  
statement?

Thank you very much.

Nik

---

<div class="post-metadata">

**Author:** ![niky81](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/51bf81/32.png) [@niky81](https://www.ruby-forum.com/u/niky81)\
**Post date:** [October 12, 2007, 12:29pm UTC](https://www.ruby-forum.com/t/multiple-tables-query/116682/2 "2007-10-12T12:29:27Z")

</div>

On 10/8/07, Nik N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> HI, I’ve read the basic books about ROR and even skimmed the recipes  
> book but can’t find a standard path for my problem.  
> I’ve to show data that due to relationships is going to take more  
> tables, not one or two but 6/7 and even 13 in some cases. Now in other  
> languages I usually write a quite long SQL statement and I get what I  
> want. But with Rails? Should I work on the model? Should I create a view  
> and then a class associated with it? Should I write the same old SQL  
> statement?

Well you could try modelling the relationships in ActiveRecord, but I  
don’t fully know how far Model.find … goes in recursing those  
relationships.  
Ideally you want it all to come back in the one query.

Still if you have that kind of SQL, I think using the raw SQL query is  
the  
best choice. Rails allows you to do this, and even encourages you to  
do this when you outgrow what Rails gives you.
