IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

i need solution for following db2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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: 1448
Location: Chicago, IL

PostPosted: Thu Apr 20, 2006 5:15 pm
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
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: 1448
Location: Chicago, IL

PostPosted: Mon Apr 24, 2006 6:23 pm
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts SDSF like solution in EJES (store com... All Other Mainframe Topics 4
No new posts A very ingenious mainframe automation... CA Products 1
No new posts Typing the CENT sign ยข on mainframe,... All Other Mainframe Topics 2
No new posts Any single step solution possible? SYNCSORT 7
This topic is locked: you cannot edit posts or make replies. CICS availability solution CICS 17
Search our Forums:

Back to Top