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

DB2 query for the distinct set


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
tecnokrat
Warnings : 1

Active User


Joined: 22 May 2009
Posts: 160
Location: Bangalore

PostPosted: Wed May 15, 2013 4:42 am
Reply with quote

Hi,
I have a requirement wherein i have to extract the data for a particular row having DISTINCT COLUMN for the cust_numb

i have been doing the below query:
Code:

  SELECT DISTINCT C1,C2
    FROM TABLE A
    WHERE A.C1  = '123'                 
        ORDER BY C1,C2
 WITH UR;                                                 


The result is as :
Code:

C1     C2
X        1
X        2
Y         1
Y         2
Z         1
A         1
B         2



But now from the above resultant set i need to get only the below rows

Code:

C1     C2
X        2
Y        2
Z        1
A        1
B        2

Back to top
View user's profile Send private message
tecnokrat
Warnings : 1

Active User


Joined: 22 May 2009
Posts: 160
Location: Bangalore

PostPosted: Wed May 15, 2013 5:31 am
Reply with quote

Hi,
I have got the Resultant set thru the Below Query:

Code:



  SELECT DISTINCT C1,C2
    FROM TABLE A
    WHERE A.C1  = '123'     
         AND A.C2 = (SELECT MAX(B.C2)
              FROM TABLE B
               WHERE B.C1 = A.C1)             
        ORDER BY C1,C2
 WITH UR; 
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 RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top