# Concat results from db query

**URL:** <https://www.ruby-forum.com/t/concat-results-from-db-query/57516>\
**Category:** Rails\
**Created:** [April 11, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/concat-results-from-db-query/57516 "2006-04-11T17:47:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Livingstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_Livingstone](https://www.ruby-forum.com/u/Paul_Livingstone)\
**Post date:** [April 11, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/concat-results-from-db-query/57516/1 "2006-04-11T17:47:38Z")

</div>

I’ve got a bunch of records coming back from a database like so

ID WORDS

1. banana apple orange
2. apple pear
3. banana orange

I want to take the records in the WORDS field and concatinate them into  
one large array so I can play around with it. How do I do this?

---

<div class="post-metadata">

**Author:** ![Paul\_Livingstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_Livingstone](https://www.ruby-forum.com/u/Paul_Livingstone)\
**Post date:** [April 11, 2006, 10:29pm UTC](https://www.ruby-forum.com/t/concat-results-from-db-query/57516/2 "2006-04-11T22:29:18Z")

</div>

I’m not 100% sure what you’re asking for, but if you have a “Word”  
activerecord table with 2 columns(id, words), here is some code that  
will  
give you what you want.

words = Word.find(:all)  
fruits = words.map{|word|word.words}.join(" “).split(” ")

---

<div class="post-metadata">

**Author:** ![Paul\_Livingstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/7c8e57/32.png) [@Paul\_Livingstone](https://www.ruby-forum.com/u/Paul_Livingstone)\
**Post date:** [April 12, 2006, 9:43am UTC](https://www.ruby-forum.com/t/concat-results-from-db-query/57516/3 "2006-04-12T09:43:32Z")

</div>

Shane S. wrote:

> I’m not 100% sure what you’re asking for, but if you have a “Word”  
> activerecord table with 2 columns(id, words), here is some code that  
> will  
> give you what you want.
> 
> words = Word.find(:all)  
> fruits = words.map{|word|word.words}.join(" “).split(” ")

That worked perfectly Shane, thanks very much.
