Question: (Closed) Sql Redundant Rows Manipulation
0
gravatar for Tom
7.3 years ago by
Tom0
Tom0 wrote:

Hi all,

I have a table with two columns. Column 2 has some redundancies which I know how to filter but when doing it I would like to merge the text from column 1 and leave only single row. (Ideally separete the text by ";"):

Col1 Col2

1 AA 2 BB 3 AA

so that I get:

Col1 Col2

1;3 AA 2 BB

Is it possible? Thanks for help

Tom

• 1.3k views
ADD COMMENTlink modified 7.3 years ago by Dave Richardson370 • written 7.3 years ago by Tom0

Which database are you using?

ADD REPLYlink written 7.3 years ago by Dave Richardson370
1
gravatar for Dave Richardson
7.3 years ago by
Cambridge, UK
Dave Richardson370 wrote:

The solution depends on the type of database you are using. If you are using a mysql database this should work:

select 
    group_concat(col_1 separator ';'),
    col_2 
from the_table
group by col_2;

For other databases you will need to look up the correct function to use in place of group_concat.

ADD COMMENTlink written 7.3 years ago by Dave Richardson370

Group_concat was the thing I was looking for, thanks.

ADD REPLYlink written 7.3 years ago by Tom0
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2005 users visited in the last hour