Home > Ask the Oracle Database / Applications Experts > Questions & Answers > The Sybase list() aggregate function
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

The Sybase list() aggregate function

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 04 September 2003

Pertaining to your answer A list of IDs in a column (March 14, 2003), I agree with you completely. In my database I do have correct design, but unfortunately I need to create a list on the query output. Using the same example I need to create a query that will display:

id   name      holdings
71   J.Smith   bonds=1047.00
72   B.White   stock=937.21, cash=211.03
73   K.Baker   bonds=3700.00, cash=42.98 stock=2044.65
...

In my case the cardinality of the foreign key can be 0..40, so concatenation of subquery results would be too ugly if possible at all. Is there any way to make this query in SQL?


>

No, not unless you include cursors, which I always mentally assign to the programming language side of the fence and not the SQL side. If you don't want to join the table to itself 40 times (and who would?), then just run a simple query with an ORDER BY, and do current/previous logic using a cursor or by looping over the result set in your programming language.

Unless you're on Sybase. Sybase Adaptive Server Anywhere (but not Adaptive Server Enterprise) has this really neat, albeit proprietary, non-standard aggregate function called list(). What it does is produce a comma-separated list of all the non-null values in a column for each group in a GROUP BY query. So your query would be:

select id, name, list(holding)
  from yourtable
group
    by id, name

Gorgeous, isn't it?


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts