Forum: Rails deployment Fetching data from two or more tables

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fa6805b16999b4b9e4ac97b7c9506067?d=identicon&s=25 Tony P. (tonyputhenveettil)
on 2009-02-16 12:15
Hi all,

Say, I have two tables (requirements & projreqs)and want to execute the
following query.
SELECT * FROM requirements WHERE(id = (SELECT req_id FROM projreqs WHERE
proj_id = ?));

Being a newbie in Ruby, I know only to extract data from one table.
Eg: Requirement.find(:all, :select, :condition) or
Requirement.find_by_sql(query).

But, how to combine two tables? Please help me out...

Appreciate your help.

Thanks,
Tony Puthenveettil
5cc224a7a2ecca1accc398f31aca24c5?d=identicon&s=25 Priyanka P. (priyanka-pathak)
on 2009-11-07 07:34
Tony Puthenveettil wrote:
> Hi all,
>
> Say, I have two tables (requirements & projreqs)and want to execute the
> following query.
> SELECT * FROM requirements WHERE(id = (SELECT req_id FROM projreqs WHERE
> proj_id = ?));
>
> Being a newbie in Ruby, I know only to extract data from one table.
> Eg: Requirement.find(:all, :select, :condition) or
> Requirement.find_by_sql(query).
>
> But, how to combine two tables? Please help me out...
>
> Appreciate your help.
>
> Thanks,
> Tony Puthenveettil

Hi,
     Extract data from two table or more table it's required that there
is some relation exist between them. As per your need you use join or
include for that.

For more information go through this url
http://api.rubyonrails.org/classes/ActiveRecord/As...

Thanks,
Priyanka Pathak
This topic is locked and can not be replied to.