0

Here is my problem:

This is the current result:

    |   Name   |  Alias  |   Role   |
        mark       mak       User
        mark       mak       Admin

This is the wanted result:

    |   Name   |  Alias  |    Role    |
        mark       mak     User, Admin

Can this be possible with SQL(using Oracle and Java EE/JPA/Hibernate right now)?

  • 1
    You might want to have a look at this question: http://stackoverflow.com/questions/1120706/is-there-an-oracle-sql-query-that-aggregates-multiple-rows-into-one-row – mal-wan Nov 09 '11 at 03:56
  • possible duplicate of [Oracle: Combine multiple results in a subquery into a single comma-separated value](http://stackoverflow.com/questions/492563/oracle-combine-multiple-results-in-a-subquery-into-a-single-comma-separated-val) – OMG Ponies Nov 09 '11 at 04:56

2 Answers2

3

GROUP_CONCAT is a MySQL function.

Here is the SQL for Oracle:

  SELECT Name, LISTAGG(Role, ',') WITHIN GROUP (ORDER BY Role) AS Roles
    FROM Your_Table
GROUP BY Name;
NullUserException
  • 83,810
  • 28
  • 209
  • 234
Softhinker.com
  • 895
  • 2
  • 11
  • 25
0

As mentioned on similar questions, this is covered in depth in the following Oracle Base article: http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php

In short you're either after the LISTAGG function or the WM_CONCAT function depending on the version of Oracle you're running.

mal-wan
  • 4,391
  • 4
  • 26
  • 37