Microsoft DN
Microsoft DN

Reputation: 10030

How to group by a column and show as one row

I have a table with following structure

SubId       Status  
---------------------------------------
001         Active
001         Partially Active

While displaying this record, I need to display this like this

SubId   Status  
---------------------------------------
001     Active/Partially active

I tried using distinct, but this returns both rows.

Any idea how can I get only 1 row instead of 2. I know it would be simple. I just cannot find it.

Upvotes: 0

Views: 72

Answers (1)

user330315
user330315

Reputation:

select subid, 
       listagg(status, '/') within group (order by null) as status
from the_table
group by subid;

Upvotes: 1

Related Questions