I am using the Sybase ASE database .
I have two tables that look like this:
Shops table:
--------------------- | ShopName | ShopID | --------------------- | Sweetie | 1 | | Candie | 2 | | Sugarie | 3 | ---------------------
Sweets table:
---------------------- | SweetName | ShopID | ---------------------- | lolly | 1 | | redlolly | 1 | | greenloly | 1 | | taffy | 2 | | redtaffy | 2 | | bluetaffy | 2 | | choco | 3 | | mintchoco | 3 | | milkchoco | 3 | | gummybees | 3 | ----------------------
I want to write a query that will generate a result that looks like this:
----------------------------------------------------- | ShopName | Sweets | ----------------------------------------------------- | Sweetie | lolly, redlolly, greenlolly | | Candie | taffy, redtaffy, bluetaffy | | Sugarie | choco, mintchoco, milkchoco, gummybees | -----------------------------------------------------
How can I do it? I need this for a Sybase ASE database. I tried the LIST() function, but I am getting an error. I checked its documentation and it turns out this feature is not available in ASE Edition.
This probably means that some kind of "dynamic sql" will be involved (I do not quite understand what this means). Can anyone help?
I might want ShopId instead of ShopName in the result table ... I still don't know for sure. I think it will not matter much. In addition, trailing commas in the Sweets column of results are not a problem. All I want is a separator without spaces.
sql join concatenation sybase-ase
jrharshath
source share