Table Join



IBM's flagship relational database management system

Table Join

Postby Vineet » Mon Jun 20, 2011 6:17 pm

Hi All,

I am Having 2 Table Table1 & Table2. Table1 Having Col. as A1,A2,A3,A4 & Table B Having Col. As B1,B2,B3,B4. Col. A1 From Table1 & Col. B1 From Table2 Is Common i.e. Both Col's Have Same Value. My Requirement is, I would like to Extract All Records From Table1, For Col. A1 Base on the Criteria where Record Present in Col. A1 But
Not Present in Table2 For B1. Below is Example.

Table1:
A1 A2 A3 A4
1 X X1 X2
2 Y Y1 Y2
3 Z Z1 Z2
4 Q Q1 Q2
5 W W1 W2

Table2:
B1 B2 B3 B4
1 X X1 X2
2 Y Y1 Y2
3 Z Z1 Z2
7 T T1 T2
8 K K1 W2

Expected Output:

Should Select Value 4 & 5 From Table1 of Col. A1.

Thanks
Kind Rgds
Vineet
 
Posts: 86
Joined: Tue Jun 19, 2007 11:38 am
Has thanked: 0 time
Been thanked: 0 time

Re: Table Join

Postby GuyC » Mon Jun 20, 2011 6:47 pm

select colA1 from stmtA
except
select colB1 from stmtB
=
select colA1 from stmtA
where not exists
(select * from stmtB
where colA1 = colB1)
=
select colA1 from stmtA
where colA1 not in
(select colB1 from stmtB)
I can explain it to you, but i can not understand it for you.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post