Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys i have a simple query that displays information from users, users can have more than 1 office assigned, now i want to group those users in offices look below:

select u.name, r.region, r.office
from user u
join region r on u.regionID=r.regionID

Results
row  name   region  office
1    SCOTT  FLORIDA MIAMI
2    SCOTT  FLORIDA TAMPA
3    SANDRA TEXAS   DALLAS
4    SOPHIA TEXAS   KILLEEN
5    SOPHIA TEXAS   DALLAS

Wanted Results
row  name   region  office
1    SCOTT  FLORIDA MIAMI
                    TAMPA
2    SANDRA TEXAS   DALLAS
3    SOPHIA TEXAS   KILLEEN
                    DALLAS


The LISTAGG function doesn't work on 10g, searching for an alternative...
Posted
Updated 20-Oct-11 4:33am
v4

I have no experience with Oracle so this from search work and is not tested.

I found the LISTAGG[^] statement, which should be available from Oracle 10g.

You statement would look like
SQL
SELECT u.name, r.region, LISTAGG(r.office, ' ') WITHIN GROUP (ORDER BY NULL)
FROM user u
JOIN region r on u.regionID = r.regionID
GROUP BY u.name, r.region
ORDER BY 1, 2 NULLS LAST

I have taken this from Oracle LISTAGG function [^].
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900