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

Finding the distinct combination from a DB2 Table


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

New User


Joined: 09 Apr 2008
Posts: 83
Location: Chennai

PostPosted: Wed Jun 05, 2013 9:05 pm
Reply with quote

Hi,
I have the a DB2 table PROD-RULE-CD which has the following columns:
Company-ID
Product-ID
State-Cd
Category-Cd
Rule-Cd

A sample data in the table is as follows:
Code:
COMP_ID    PROD_ID        ST_CD       CAT_CD          RULE_CD
=========================================
01               141                AK               A                  2006
01               141                AK               R                  0516
01               141                AL                A                  2006
01               141                AL                R                  0516
01               141                AZ               A                  2001
01               141                AZ               S                  0063
01               141                AZ               R                  0516
01               141                CA               A                  2001
01               141                CA               A                  2006
01               141                CA               R                  0516

In this table, I have a Company-ID and Product ID available in each state and a rule-cd applies to the Company-Code and Product ID in that state.
Now, I want to find out the unique Rule-CD combinations which are present in this table.
So, in the above data sample, the State of AK and AL has the same Rule-CD combinations i.e. the Rule Code 2001 and 0516 apply to both the states. AZ and CA have a different rule-cd combinations. For AZ, the rule-cd which can be applied is 2001, 0063 and 0516. For CA, the rule-cd is 2001, 2006 and 0516.

Can I find out the unique combinations in a query? I tried ranking but that does not work.
Back to top
View user's profile Send private message
Gary McDowell

Active User


Joined: 15 Oct 2012
Posts: 139
Location: USA

PostPosted: Wed Jun 05, 2013 9:29 pm
Reply with quote

Some form of...
SELECT DISTINCT row_name
may help.?.
Back to top
View user's profile Send private message
rahuindo

New User


Joined: 09 Apr 2008
Posts: 83
Location: Chennai

PostPosted: Wed Jun 05, 2013 9:36 pm
Reply with quote

Hi Gary,
Distinct does not work because each row is distinct so it returns all the rows. I do have a logic to implement in COBOL but just checking if anyone in forum have some idea to implement in DB2 query.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Wed Jun 05, 2013 9:50 pm
Reply with quote

Could you please let me know the expected output with code tags on?
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 Finding and researching jobs All Other Mainframe Topics 0
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts VB to FB - Finding LRECL SYNCSORT 4
No new posts Multiple table unload using INZUTILB DB2 2
Search our Forums:

Back to Top