Boris Mitioglov
Boris Mitioglov

Reputation: 1182

How to union two rows in one by connecting it on some cell in SQL?

My query:

-

I have 2 results of my query:

SA01 |  False   | SA01  |   False | No |    Yes |   [NULL] |    VA - HRD 1
SA01 |  False   | SA01  |   False | No |    Yes |   [NULL] |    VA - NOVA 1  

I want to union them into one row and different cell values should union into one like this:

SA01  | False  |SA01  | False  |No  |Yes  | [NULL]  |   VA - HRD 1, VA - NOVA 1

Is it possible in SQL?

Upvotes: 0

Views: 85

Answers (1)

René Nyffenegger
René Nyffenegger

Reputation: 40499

You want to uselistagg.

select
  a, b, c, listagg(col_with_VA_Values, ', ') within group (order by ...)
from
  table
group by
  a, b, c;

As already was pointed out, without table definition (create table...) and example data (insert into .... values (...)) you can only expect a quite vague answer.

Upvotes: 2

Related Questions