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
 

 

Need a SQL query to do the following in two tables

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

New User


Joined: 29 May 2006
Posts: 0

PostPosted: Thu Aug 24, 2006 10:22 am    Post subject: Need a SQL query to do the following in two tables
Reply with quote

I need a query to do the following in two tables say AAA and BBB

AAA has columns a,b,c,d,e,f,g,h

BBB has columns h,i,j,k

I have to fetch rows such that a,b,c,d,e,f,g should be equal
h should be different
i,j,k -any one of the values shopuld differ



example

a b c d e f g h i j k

1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 17 9 10 14

or

a b c d e f g h i j k

1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 17 9 14 11

or

a b c d e f g h i j k

1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 17 14 10 11



Thanks in advance
Back to top
View user's profile Send private message

red_roses

New User


Joined: 31 Oct 2005
Posts: 27

PostPosted: Thu Aug 24, 2006 10:07 pm    Post subject:
Reply with quote

you say a,b,c,d,e,f,g should be equal ... equal to what.. as per your description BBB has none of the rows from a to g. so on what are you going to match..????
Back to top
View user's profile Send private message
priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Sat Sep 02, 2006 9:53 am    Post subject: Re: Need a SQL query to do the following in two tables
Reply with quote

I hope, I understood what you wanted to convey... else excuse me for wasting your time...

Code:
SELECT * FROM
   (SELECT * FROM
      (SELECT * FROM AAA, BBB WHERE AAA.H = BBB.H)
   GROUP BY A,B,C,D,E,F,G HAVING COUNT(*) >1)
GROUP BY I,J HAVING COUNT(*) >1
UNION
SELECT * FROM
   (SELECT * FROM
      (SELECT * FROM AAA, BBB WHERE AAA.H = BBB.H)
   GROUP BY A,B,C,D,E,F,G HAVING COUNT(*) >1)
GROUP BY J,K HAVING COUNT(*) >1
UNION
SELECT * FROM
   (SELECT * FROM
      (SELECT * FROM AAA, BBB WHERE AAA.H = BBB.H)
   GROUP BY A,B,C,D,E,F,G HAVING COUNT(*) >1)
GROUP BY I,K HAVING COUNT(*) >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 Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SPUFI -- Joining 3 tables – data in... Sysaron DB2 2 Wed Mar 08, 2017 4:18 am
No new posts To know activities on db2 tables ashek15 DB2 4 Fri Mar 03, 2017 11:23 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm


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