Is there a way, in ORACLE, to join multiple row lines into a single one, using two tables, where the final values are separated by commas?
oracle, sql
Solution
Take a look at LISTAGG
http://www.oracle-base.com/articles/misc/StringAggregationTechniques.php
Something like:
SELECT NAME, LISTAGG(CAR, ',') WITHIN GROUP (ORDER BY CAR) AS CARS
FROM (SELECT NAME,CAR
FROM TABLE1, TABLE2
where TABLE1.IdN=TABLE2.IdC)
GROUP BY NAME;
Problem
Is there a way to join multiple row lines a single one using two tables where the values are separated by commas in ORACLE? Example: Table1 ``` IdN Name --------- 1 A 2 B 3 C ``` Table 2 ``` IdC Car ------------ 1 Ferrari 1 BMW 2 SEAT 2 FIAT 3 FORD ``` Result as: ``` A Ferrari,BMW B SEAT,FIAT C FORD ``` I was wondering if there is something like this: ``` SELECT NAME,CAR FROM TABLE1, TABLE2 where TABLE1.IdN=TABLE2.IdC ``` This returns something like: A FERRARI A BMW B SEAT B FIAT C FORD Is there a simple way to "concat" into a row with comma-separated-values ?