0

This is probably a simple question that for some reason I just cannot see the answer. Here is sample data:

+----+----------+---------------------------+
| ID | F_Key_ID |        Desc_Text          |
+----+----------+---------------------------+
|  1 |      15  | This is an example        |
|  2 |      15  | that I wished worked      |
|  3 |      15  | correctly                 |
|  4 |      21  | Unique entry              |
|  5 |      18  | The Eagles are            |
|  6 |      18  | the best football team.   |
+----+----------+---------------------------+

Please excuse the noob table. How awful is that?!

What I'd like is some SQL that takes the text common to each F_Key_ID and concatenates it together like this:

+----------+---------------------------------------------------+
| F_Key_ID |                    Concat_Text                    |
+----------+---------------------------------------------------+
|       15 | This is an example that I wished worked correctly |
|       21 | Unique entry                                      |
|       18 | The Eagles are the best football team.            |
+----------+---------------------------------------------------+

Thanks in advance!

Doubledown
  • 458
  • 1
  • 6
  • 13
  • 3
    Please tag your question with your database. And, you can search " aggregate string concatentation" to get the answer to your question. – Gordon Linoff Aug 21 '15 at 20:42
  • possible duplicate of [Concatenate many rows into a single text string?](http://stackoverflow.com/questions/194852/concatenate-many-rows-into-a-single-text-string) – Bulat Aug 22 '15 at 05:00

1 Answers1

1

So after taking Gordon's advice and visiting another page, I found this answer for oracle:

SELECT F_Key_ID,
replace(wm_concat(Desc_Text), ',' , ' ') AS Concat_Text
FROM databaseName
GROUP BY F_Key_ID;

Community
  • 1
  • 1
Doubledown
  • 458
  • 1
  • 6
  • 13
  • 2
    If possible use `listagg()` instead of wm_concat. _[WM_CONCAT is undocumented and unsupported by Oracle](http://psoug.org/definition/wm_concat.htm)_ – Ponder Stibbons Aug 21 '15 at 23:40