# Can I do a query SQL with various tables using find\_by\_sql?

**URL:** <https://www.ruby-forum.com/t/can-i-do-a-query-sql-with-various-tables-using-find-by-sql/184651>\
**Category:** Ruby\
**Created:** [March 5, 2010, 9:12pm UTC](https://www.ruby-forum.com/t/can-i-do-a-query-sql-with-various-tables-using-find-by-sql/184651 "2010-03-05T21:12:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jorgegetafe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eada6e/32.png) [@jorgegetafe](https://www.ruby-forum.com/u/jorgegetafe)\
**Post date:** [March 5, 2010, 9:12pm UTC](https://www.ruby-forum.com/t/can-i-do-a-query-sql-with-various-tables-using-find-by-sql/184651/1 "2010-03-05T21:12:40Z")

</div>

Hello.

I need to do a query with various tables, but I want to use something  
like find\_by\_sql.

It’s say, i want to make the next query:

SELECT field\_table1,field\_table1,field\_table2  
FROM table1, table2  
WHERE table1.id=table2.table1\_id

And, How can I access its values?

Greetings and thanks.

---

<div class="post-metadata">

**Author:** ![jorgegetafe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/eada6e/32.png) [@jorgegetafe](https://www.ruby-forum.com/u/jorgegetafe)\
**Post date:** [March 5, 2010, 11:35pm UTC](https://www.ruby-forum.com/t/can-i-do-a-query-sql-with-various-tables-using-find-by-sql/184651/2 "2010-03-05T23:35:14Z")

</div>

Jorge alejandro Mendoza torres wrote:

> Hello.
> 
> I need to do a query with various tables, but I want to use something  
> like find\_by\_sql.
> 
> It’s say, i want to make the next query:
> 
> SELECT field\_table1,field\_table1,field\_table2  
> FROM table1, table2  
> WHERE table1.id=table2.table1\_id

It depends on what database access library you are using. There are many  
to choose from; there are direct native APIs to most databases, or the  
low-level DBI which wraps these. They’ll all work at the level of SQL  
statements like SELECT. Then there are higher-level abstractions like  
ActiveRecord, Sequel, DataMapper, og, …

“find\_by\_sql” sounds like something from ActiveRecord.

If your question is specifically about ActiveRecord, you might be better  
of asking in a Rails mailing list.
