# SQL - Merging fields from two tables into one, including dup

**URL:** <https://www.ruby-forum.com/t/sql-merging-fields-from-two-tables-into-one-including-dup/147476>\
**Category:** Rails\
**Created:** [September 2, 2008, 9:17am UTC](https://www.ruby-forum.com/t/sql-merging-fields-from-two-tables-into-one-including-dup/147476 "2008-09-02T09:17:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinathbtech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7bcc69/32.png) [@srinathbtech](https://www.ruby-forum.com/u/srinathbtech)\
**Post date:** [September 2, 2008, 9:17am UTC](https://www.ruby-forum.com/t/sql-merging-fields-from-two-tables-into-one-including-dup/147476/1 "2008-09-02T09:17:15Z")

</div>

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
