I have 2 tables in Oracle: table1 and table2 (we have a very unimaginative DBA!)
table1 has column id (and a few others).
table2 has columns id, table1id and code. table1id is a foreign key to table1.
Usually there is 1 table2 row for each table1 row, but sometimes there are 2 table2 rows for a table1 row, and very occasionally 3.
What I need is a single 'code' value for each table1 row. If there is more than one coresponding table2 row, I need a concatenated string of all values returned, so the result might look like this:
table1.id code 1 a 2 b 3 a b 4 a b c Any idea how this can be achieved? If it were SQL Server I'd write a function, although this would be slower than I would like. However I'm not as hot in Oracle as I am in SQL Server.