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
 

 

Query to select some combination of records.

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

New User


Joined: 30 Mar 2006
Posts: 11

PostPosted: Wed Jan 03, 2007 7:40 pm    Post subject: Query to select some combination of records.
Reply with quote

Dear All,

I have to select some combination of rows from the table as follows


Lets say, Column A is of Char(6) and Column B is of Char(12) in a table TAB1.

The records in the table is as follows..

Table : TAB1

A B
- -
102345 123456789100
102345 123456789100
102345 123456789101
102345 123456789101
102321 123456789123
102322 123456789124
102343 123456789125
102344 123456789126
102344 123456789127
102347 123456789128


From the above table, I need the list of rows where Column A is having more than one unique column B value

I mean the query should result as below

Output:

102345 123456789100
102345 123456789100
102345 123456789101
102345 123456789101

102344 123456789126
102344 123456789127


Since 102345 and 102344 has more than one unique value in Column B.

Please kindly let me know the query if available.

Thanks in advance

Regards.
Rajesh
Back to top
View user's profile Send private message

DavidatK

Active Member


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

PostPosted: Thu Jan 04, 2007 2:00 am    Post subject: Re: Query to select some combination of records.
Reply with quote

Code:

SELECT A, B                                 
  FROM DB2.TAB1                           TT1         
 WHERE EXISTS                               
       (SELECT COUNT(DISTINCT B)           
          FROM DB2.TAB1                   TT2     
         WHERE TT2.A = TT1.A               
        HAVING COUNT(DISTINCT B) > 1       
        )                                   
;
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
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 Removing Duplicates based on certain ... chandracdac DFSORT/ICETOOL 8 Fri Dec 09, 2016 4:40 am


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