Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Finding the distinct combination from a DB2 Table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Finding the distinct combination from a DB2 Table
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    Post subject:
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    Post subject:
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

Moderator


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

PostPosted: Wed Jun 05, 2013 9:50 pm    Post subject:
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    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
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Row-Numbers of distinct rows? Auryn DB2 1 Thu Oct 20, 2016 4:38 pm
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Command UNIQUE CONSTRAINT on any tabl... rohanthengal DB2 2 Thu Aug 18, 2016 3:48 pm
No new posts Updating online Db2 table kishpra DB2 3 Fri Aug 12, 2016 2:44 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us