0

I need to get a result table from an sql query.

Suppose i have 2 columns A,B. The column A contains multiple values which can be similar or distinct. Column B contains only 2 values 1 or 2. I tried the group by but i am getting all the results as different rows.

How can i expect a query which can return all the distinct values of A in a single row with one value of B.

Rough Data

A B
ex1 1
ex2 1
ex3 2
ex4 2

Expected Data

A B
ex1,ex2 1
ex3,ex4 2
select ....
group by a,b
Thom A
  • 88,727
  • 11
  • 45
  • 75
  • 3
    @erik258 you mean STRING_AGG :) https://learn.microsoft.com/en-us/sql/t-sql/functions/string-agg-transact-sql?view=sql-server-ver16 – siggemannen Feb 22 '23 at 16:48

0 Answers0