View previous topic :: View next topic
|
Author |
Message |
krunalbafna Warnings : 1 Active User
Joined: 18 Jan 2010 Posts: 143 Location: Pune
|
|
|
|
Hi Team,
I have two table:
Table A and Table B
Both have follwing three fields in common:
Employee Number :
IN A defined as decimal
IN B defined as CHar(10)
Emplye Code:
Table A and B defined as X(1)
Emp id:
Table A: As S9(7) comp-3
Table B: as char(12)
my query should give only those combination of 3 varibles from table which are not present in Table -B
I used following query:
SELECT
A.EMPNO,
A.EMPCODE,
A.EMPID
FROM EMPA A, EMPPA B
WHERE A.EMPNO <> CAST(B.EMPNO AS DECIMAL(10)) AND
A.EMPCODE <> B.EMPCODE AND
A.EMPID <> CAST(B.EMPID AS DECIMAL(12))
ABOVE query results in output which are present in the table b. It contradicts my requirement.
May you please guide where i am going wrong.
Regards,
Krunal |
|
Back to top |
|
|
bhairon singh rathore
New User
Joined: 19 Jun 2008 Posts: 91 Location: banglore
|
|
|
|
select CAST(B.EMPNO AS DECIMAL(10)) ,B.EMPCODE , CAST(B.EMPID AS DECIMAL(12))
with above selected value and compare both ......you will get the reason for the same |
|
Back to top |
|
|
krunalbafna Warnings : 1 Active User
Joined: 18 Jan 2010 Posts: 143 Location: Pune
|
|
|
|
HI Bhairon,
As you mentioned i used the above query and can find that values taken for the comaparision are different.
Now how can we execute or refine the query to get only those records from table A which are not present in table B depending on combination
Employee Number,EMP CODE and EMP ID |
|
Back to top |
|
|
bhairon singh rathore
New User
Joined: 19 Jun 2008 Posts: 91 Location: banglore
|
|
|
|
Hi Krunal,
Can you please show some of the result with both values in select. |
|
Back to top |
|
|
krunalbafna Warnings : 1 Active User
Joined: 18 Jan 2010 Posts: 143 Location: Pune
|
|
|
|
from table B it is only taking same values
A.EMPNO B.EMPNO A.EMPCODE A.EMPID
008 171 Z 303010
086 171 F 7757
086 171 L 858009
110 171 L 7758460
110 171 S 2984821
110 171 Z 7678571
167 171 S 17946669
167 171 Z 81336697
133 171 S 13608461
133 171 Z 00597832 |
|
Back to top |
|
|
krunalbafna Warnings : 1 Active User
Joined: 18 Jan 2010 Posts: 143 Location: Pune
|
|
|
|
Hi team
Any suggestion or help... |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
this join will create a Cartesian product except the inner join on the three columns :
table 1 table2
row1 row1
row2 row2
row3 row3
row1 joined row2 qualifies your where clause
row1 joined row3 qualifies your where clause
row2 joined row1 qualifies your where clause
row2 joined row3 qualifies your where clause
row3 joined row1 qualifies your where clause
row3 joined row2 qualifies your where clause
what you probably want is something like EXCEPT in DB2 V9
or where not exists() pre V9
Code: |
select dbname, name from sysibm.systablespace
except
select dbname, tsname from sysibm.systables
with ur |
Code: |
select * from sysibm.systablespace TS
where not exists (select * from sysibm.systables TB
where TB.dbname = TS.DBNAME and TB.tsname = TS.NAME)
with ur |
will give you everything from tablespace which isn't in tables |
|
Back to top |
|
|
mallik4u
New User
Joined: 17 Sep 2008 Posts: 75 Location: bangalore
|
|
|
|
Hi GUYC,
Thanks for giving information about EXCEPT keyword. It is really very usefull.
Can you share any document/url on new/updated db2 v9? |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
Back to top |
|
|
|