Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert Merging fields from two tables...

Replytotopic

Merging fields from two tables into one, including duplicates

Posted in Forums : Ask a Rails expert

 
Profile

Authority 25
Posting Rating 0
Sign in to rate this post

Hi,

I have two tables, nutritions and food_options.
nutritions has two fields, fooditem_id, taken and .
food_options has two fields, fooditem_id and taken.
fooditem_id in nutritions and food_options will point to id in food_items table(third table).

I want to select all records from nutritions and food_options into a new table, C with Fields fooditem_id and taken. This means I need to combine the values of fooditem_id in nutritions and fooditem_id in food_options into one field (fooditem_id), including the duplicates in both tables.

EX:
nutritions
id fooditem_id taken
1 23 1
2 23 1

food_options
id fooditem_id taken
1 34 1

C
id fooditem_id taken
1 23 1
2 23 1
3 34 1

How can I do this?

thanks,
srinath

Replytotopic

Other Recent Topics

Ask a Rails expert : Ruby Builder

Ask a Rails expert : Better programming skills

Ask a Rails expert : Select Option

Ask a Rails expert : Updating ruby version on windows

Ask a Rails expert : Periodicall Ajax Calls and Session Expiry

Ask a Rails expert : Sub queries in RoR

Ask a Rails expert : Remembering associations

Ask a Rails expert : Keeping the databse clean

Ask a Rails expert : How to redirect single app to 2 different URLs

Ask a Rails expert : Dealing with nested models

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel