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

Need a SQL query to do the following in two tables


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
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
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
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: 1448
Location: Chicago, IL

PostPosted: Sat Sep 02, 2006 9:53 am
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 All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts DB2 Query to get the count of Unique ... DB2 2
No new posts Question regarding ISPF tables with T... TSO/ISPF 11
No new posts To join 2 tables and to join 3rd tabl... DB2 8
No new posts Need help with ADABAS query (COBOL-AD... All Other Mainframe Topics 1
No new posts RC query -Time column CA Products 3
Search our Forums:


Back to Top