Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
i need solution for following db2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
muneer

New User


Joined: 06 Mar 2006
Posts: 3

PostPosted: Thu Apr 20, 2006 4:49 pm    Post subject: i need solution for following db2
Reply with quote

I need solution to followin task:

let us say table has fields like subgroup and members
a subgroup may have more than one members

subgroup member
x 1
x 2
x 2
y 7
y 5
z 2
z 3

i need all subgroup with one member

Results
x 1
y 7
z 3
Back to top
View user's profile Send private message

priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Thu Apr 20, 2006 5:15 pm    Post subject: Re: i need solution for following db2
Reply with quote

What are the conditions based on which you are selecting MEMBER.

Regards,
Priyesh.
Back to top
View user's profile Send private message
muneer

New User


Joined: 06 Mar 2006
Posts: 3

PostPosted: Mon Apr 24, 2006 1:09 pm    Post subject: Re: i need solution for following db2
Reply with quote

Sorry for late

There was no search condition

only any one member for each subgroup i need
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Mon Apr 24, 2006 6:23 pm    Post subject: Re: i need solution for following db2
Reply with quote

You can not say randomly to pick out any member, when SQL would run it'll check all the rows of a TABLE.

Check for an ICETOOL on Table extract if you just want to pick up first such member.

Regards,
Priyesh.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Apr 25, 2006 4:51 am    Post subject: Re: i need solution for following db2
Reply with quote

muneer,

This SQL will select the 'SUBGROUP' with the minimum 'MEMBER' value.
You indicated on your last post that ANY row would work. I created a SESSION.TEMP_TBL and loaded it with the values you suplied.

Code:


SELECT DISTINCT SUBGROUP, MEMBER           
  FROM SESSION.TEMP_TBL             TT     
 WHERE MEMBER =                           
       (SELECT MIN(MEMBER)                 
          FROM SESSION.TEMP_TBL     TT2   
         WHERE TT2.SUBGROUP = TT.SUBGROUP 
        )                                 
;                                         

  +--------------------+
  | SUBGROUP | MEMBER  |
  +--------------------+
1_| X        |     1   |
2_| Y        |     5   |
3_| Z        |     2   |
  +--------------------+
                       


Dave
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Apr 25, 2006 4:59 am    Post subject: Re: i need solution for following db2
Reply with quote

OR,

Code:


SELECT DISTINCT SUBGROUP, MIN(MEMBER) AS MEMBER
  FROM SESSION.TEMP_TBL                       
 GROUP BY SUBGROUP                             
;                                                               

  +--------------------+
  | SUBGROUP | MEMBER  |
  +--------------------+
 1_| X        |     1   |
 2_| Y        |     5   |
 3_| Z        |     2   |
  +--------------------+
                         
                         


Dave
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Need help in design the solution ritnihi PL/I & Assembler 1 Tue Dec 22, 2015 1:48 pm
No new posts Please give me solution(OUTPUT ) for ... sivareddy123 COBOL Programming 4 Mon Feb 02, 2015 1:33 pm
No new posts Delimited File -Unable to Find solution Dimpy Udhani JCL & VSAM 7 Mon Nov 24, 2014 11:40 am
No new posts MQ Solution Designer Certification Appu IBM Tools 0 Mon Jul 07, 2014 11:25 am
No new posts ICETOOL/Joinkeys Solution for Group B... ksouren007 DFSORT/ICETOOL 3 Wed Mar 05, 2014 4:04 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us