If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Grouping Results

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-07-04, 14:06
ansonee ansonee is offline
Registered User
 
Join Date: Feb 2002
Location: Minneapolis, MN
Posts: 253
Grouping Results

I have a syntax question but not too sure how to phrase it, so I apologize in advance if it gets to be too wordy.

I'm querying a series of tables which have parent/child relationship. Let's say the parent table has five unique row identifiers(keys). The child table has five children per parent key.

Is it possible to perform a query that will list this as though it were a tree view? For example, a normal select I ran turned out like this:

PARENT DESC CHILD MISC
1 rowone 45 junk1
1 rowone 46 junk2
1 rowone 55 junk3
1 rowone 99 junk4
2 rowone 23 jun1
2 rowone 11 jun2
2 rowone 34 jun3

Is it possiblee to get this somehow:?

PARENT DESC CHILD MISC
1 rowone 45 junk1
46 junk2
55 junk3
99 junk4
2 rowone 23 jun1
11 jun2
34 jun3

Might be a bit much to ask but any help would be appreciated. I've attached an actual screen shot of trhe data if that may be of any help.

Thanks in advance!
Attached Images
File Type: bmp results.bmp (1.99 MB, 102 views)
__________________
Anthony Robinson

"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."
Reply With Quote
  #2 (permalink)  
Old 04-07-04, 14:52
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Isn't presentation what applications are for?
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 04-07-04, 15:03
ansonee ansonee is offline
Registered User
 
Join Date: Feb 2002
Location: Minneapolis, MN
Posts: 253
Extremely good point...that's what I said....
__________________
Anthony Robinson

"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."
Reply With Quote
  #4 (permalink)  
Old 04-07-04, 15:37
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: Grouping Results

Quote:
Originally posted by ansonee

Is it possiblee to get this somehow:?

PARENT DESC CHILD MISC
1 rowone 45 junk1
46 junk2
55 junk3
99 junk4
2 rowone 23 jun1
11 jun2
34 jun3

I think SQL Cookbook contains some examples, under "Recursive queries", which can give you an idea.
Reply With Quote
  #5 (permalink)  
Old 04-08-04, 03:59
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
Something like this...
Code:
create table grouping_test
(col1 char(1)
,col2 char(1)
);

insert into grouping_test
values ('A','X')
,      ('A','Y')
,      ('A','Z')
,      ('B','P')
,      ('B','Q')
,      ('B','R')
,      ('C','A')
,      ('A','W')
,      ('C','B');

select case rn
         when 1 then col1
         else ''
       end , col2
from ( select col1, col2, row_number() over (partition by col1 order by col1, col2) rn
       from grouping_test
     ) temp_table
;
Damian
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On