Quote:
|
Originally Posted by sarikan
Hi,
I have a table on which I can execute group by and get back a set of results like these:
Name1 SessionId1
Name2 SessionId1
Name3 SessionId1
Name4 SessionId2
Name5 SessionId2
Name6 SessionId2
the problem is, I need to use these rows by grouping them again in my application. all rows with sessionId1 should be under a container type instance (like an arraylist in java), and all rows with sessionId2 should go under another container instance.
Is there any way I can use sql to get back some sort of containers? Can I use a custom type for example? If I can handle this in the db, that'd really save me a lot of cpu processing, but my last contact with db layer has been a while ago
|
If I understand well, you want some kind of "aggregate concatenation": grouping by SessionID, such that the name field for SessionID1 contains 'Name1'||','||'Name2'||','||'Name3'.
That's the closest you can come to a "list container" in a relational context, since table cells have to be "atomic", i.e., cannot be composite.
Searching for "aggregate concatenation" in this forum yields e.g.
SQL - Multiple text values in the same field which in turn points to a worked-out example:
query, special transpose and merge of data
Note that this requires that your database supports recursive CTEs, a relatively new SQL syntax feature.