0

I have database as follows

A     B
1   ereee
2   ereee
2   sdfsd
3   nere
1   sdfsd

I want to have a data which will be as follows

A     B
1   ereee,sdfsd
2   ereee,sdfsd
3   nere

what is the query?

spenibus
  • 4,339
  • 11
  • 26
  • 35
  • possible duplicate of [Simulating group\_concat MySQL function in SQL Server?](http://stackoverflow.com/questions/451415/simulating-group-concat-mysql-function-in-sql-server) – spenibus Jul 30 '15 at 09:50

1 Answers1

1

Your question didn't specify what kind of database. The following works for MySQL and perhaps a few others:

GROUP_CONCAT(expr)
This function returns a string result with the concatenated non-NULL values from a group.

https://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat

SELECT A, GROUP_CONCAT(B SEPARATOR ',') AS B 
FROM table
GROUP BY A

Update 2015-07-30 09:43 +0000

Since it's been made clear that this is about SQL Server 2005, the question might be a duplicate of this:

Simulating group_concat MySQL function in Microsoft SQL Server 2005?

Community
  • 1
  • 1
spenibus
  • 4,339
  • 11
  • 26
  • 35