IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New And here I always thought this was impossible!
Suppose that you have a table with the fields (some_id, some_text, order_id). Suppose further that you're asked for a query that returns (some_id, all text entries concatenated together here).

Sounds impossible, right? Well here is a pure SQL solution for Oracle (using several non-ANSI extensions, of course):
\nSELECT some_id\n  , SUBSTR(txt, 3) as concatenated_text\nFROM (\n    SELECT some_id\n      , SYS_CONNECT_BY_PATH(some_text, ', ') as txt\n    FROM (\n        SELECT some_id\n          , some_text\n          , RANK() OVER (\n              PARTITION BY some_id\n              ORDER BY order_id\n            ) as id\n          , RANK() OVER (\n              PARTITION BY some_id\n              ORDER BY order_id DESC\n            ) as r\n        FROM some_table\n      )\n    START WITH id = 1\n    CONNECT BY PRIOR id = id - 1\n      AND PRIOR some_id = some_id\n  )\nWHERE r = 1\n

I got the idea for this from [link|http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:229614022562#48352191372887|http://asktom.oracle...62#48352191372887] but working out the details wasn't as simple as I thought it would be. (Plus his formatting was horrible.)

Cheers,
Ben
I have come to believe that idealism without discipline is a quick road to disaster, while discipline without idealism is pointless. -- Aaron Ward (my brother)
New Interesting
I've spent quite a bit of time banging my head on the wall trying to figure a way how to do that in older versions SQL Server. I believe you can build user defined aggregate functions in 2005, which should be able to solve that problem.

Amusingly, MySQL has a built in function, group_concat, that does exactly that. It's terribly nonstandard, but probably very handy for exactly this sort of situation. I'm guessing it is an example of itch scratching on somebodies part.

Jay
New Yup - for walking trees
Been in there forever.
I never needed it, but it was always in the back of my mind in case I did.
     And here I always thought this was impossible! - (ben_tilly) - (2)
         Interesting - (JayMehaffey)
         Yup - for walking trees - (broomberg)

Nobody can spell “fuchsia”.
34 ms