I work with two objects: Itemand Attribute, which look something like this:
Item
itemId
Attribute
attributeId
name
An Itemhas Attributes, as indicated in the association table:
ItemAttribute
itemId
attributeId
When this data reaches the client, it will be displayed with a line behind Item, and each line will have a list Attributeby name. For instance:
Item Attributes
---- ----------
1 A, B, C
2 A, C
3 A, B
The user will be able to sort by column Attributes, so we need to sort the data as follows:
Item Attributes
---- ----------
3 A, B
1 A, B, C
2 A, C
Currently we are getting one row of data per row ItemAttribute. Primarily:
SELECT Item.itemId,
Attribute.name
FROM Item
JOIN ItemAttribute
ON ItemAttribute.itemId = Item.itemId
JOIN Attribute
ON Attribute.attributeId = ItemAttribute.attributeId
ORDER BY Item.itemId;
Which gives the result, for example:
itemId name
------ ----
1 A
1 B
1 C
2 A
2 C
3 A
3 B
ORDER BY . , , , , Attribute , , . , , Oracle , - - :
itemId name
------ ----
3 A
3 B
1 A
1 B
1 C
2 A
2 C
Oracle LISTAGG ; Attribute.name , , 4000 , .
, Oracle SQL (11gR2)?