Forum: Rails deployment Fetching data from two or more tables

442f1c05ac02e1934cde594a185807a9?d=identicon&s=25 Tony Puthenveettil (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
Ac4123f7af05808b1ec7a1bbdb69ce07?d=identicon&s=25 Priyanka Pathak (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.