Fetching data from two or more tables


#1

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 P.


#2

Tony P. 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 P.

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

Thanks,
Priyanka P.