subbu
subbu

Reputation: 1

Merge text in a single column

I have a table, sample records are shown below -

Name       ID      C.NO   Text
----       ----    ----   ----
ABC        A       1      first
ABC        A       2      xyz
ABC        A       3      AMD
ZSD        B       1      hoho
ZSD        B       2      hihi

now my output would be like -------

Name      ID      Text
----      ---     ----
ABC       A       firstxyzAMD
ZSD       B       hohohihi

kindly help me providing sql statement

Upvotes: 0

Views: 442

Answers (3)

Niraj Kumar
Niraj Kumar

Reputation: 754

Well, following query worked in my table (MySQL) and I got the exact result as per your specification

select 
    Name,
    ID,
    group_concat(Text SEPARATOR '')
from table_name
group by ID

Upvotes: 0

Remco K.
Remco K.

Reputation: 717

MySQL:

SELECT
   GROUP_CONCAT(`text`, '' SEPARATOR '') AS `newtext`
FROM [table]
GROUP BY `name`;

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1271231

In SAP Hana, you would use string_agg():

select name, id, string_agg(text, '')
from t
group by name, id;

The equivalent function in MySQL is group_concat(); in Oracle, listagg().

Upvotes: 3

Related Questions