-2

Let's assume that I have one table with two columns A and B. In A column I have number for example 1,2,3. In B column I have some characters (not the special ones). It looks like this :

Column A: 1   1   2   2   3

Column B: a   b   c   d   e

My desired output would be :

Column A: 1      2   3
Column B: a-b   c-d  e
Eric Brandt
  • 7,886
  • 3
  • 18
  • 35
  • 1
    Possible duplicate of [How to concatenate text from multiple rows into a single text string in SQL server?](https://stackoverflow.com/questions/194852/how-to-concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql-serv) – Sebastian Brosch Aug 14 '19 at 21:43

1 Answers1

0

You can use aggregation:

select a, min(b) + '-' + max(b)
from t
group by a;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786