Question

I am using mysql , Table with 2 Columns

Col1  |  Col1 
------+-------+
a@a   |   ab  |
a@a   |   cd  |
b@b   |   ab  |
b@b   |   cd  |

I want result like this

Col1  |  Col1 
------+--------+
a@a   |   abcd |
b@b   |   abcd |

How can i achieve this using SQL please help me. Thanks.

Was it helpful?

Solution

Use GROUP_CONCAT with no SEPARATOR like so:

SELECT col1, GROUP_CONCAT(col2 SEPARATOR '') AS col2
FROM tablename
GROUP BY col1;

See it in action here:

This will give you:

| COL1 | COL2 |
---------------
|  a@a | abcd |
|  b@b | abcd |
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top