Doc Holiday
Doc Holiday

Reputation: 10254

Oracle SQL put values of a column in one row

I have a query were im returning a 3 columns

ID    NUMBER    LETTER
123    1        a
124    2        b
123    1        c
123    1        d

what I want to do is have a row like

ID    NUMBER    LETTER
123    1        a,c,d

when I the ID and NUMBER column is the same is one value and t

Upvotes: 0

Views: 1991

Answers (1)

Taryn
Taryn

Reputation: 247620

In Oracle 11g, you can use the LISTAGG() function:

select id,
  number,
  listagg(letter, ', ') within group(order by id, number) as letter
from yourtable
group by id, number;

See SQL Fiddle with Demo

Upvotes: 3

Related Questions