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
 

 

Joint query

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

Active User


Joined: 18 Jan 2010
Posts: 143
Location: Pune

PostPosted: Fri May 21, 2010 10:55 am    Post subject: Joint query
Reply with quote

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
View user's profile Send private message

bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Fri May 21, 2010 11:47 am    Post subject:
Reply with quote

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
View user's profile Send private message
krunalbafna
Warnings : 1

Active User


Joined: 18 Jan 2010
Posts: 143
Location: Pune

PostPosted: Fri May 21, 2010 11:56 am    Post subject:
Reply with quote

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
View user's profile Send private message
bhairon singh rathore

New User


Joined: 19 Jun 2008
Posts: 91
Location: banglore

PostPosted: Fri May 21, 2010 12:10 pm    Post subject:
Reply with quote

Hi Krunal,

Can you please show some of the result with both values in select.
Back to top
View user's profile Send private message
krunalbafna
Warnings : 1

Active User


Joined: 18 Jan 2010
Posts: 143
Location: Pune

PostPosted: Fri May 21, 2010 12:13 pm    Post subject:
Reply with quote

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
View user's profile Send private message
krunalbafna
Warnings : 1

Active User


Joined: 18 Jan 2010
Posts: 143
Location: Pune

PostPosted: Fri May 21, 2010 1:25 pm    Post subject:
Reply with quote

Hi team
Any suggestion or help...
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri May 21, 2010 2:06 pm    Post subject:
Reply with quote

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
View user's profile Send private message
mallik4u

New User


Joined: 17 Sep 2008
Posts: 75
Location: bangalore

PostPosted: Fri May 21, 2010 4:38 pm    Post subject:
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri May 21, 2010 5:27 pm    Post subject:
Reply with quote

except: http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.apsg/db2z_combineresultmultipleselect.htm

what's New : http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc/db29lib.htm

Redbooks
Technical : http://www.redbooks.ibm.com/abstracts/SG247330.html
Performance : http://www.redbooks.ibm.com/abstracts/sg247473.html
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 JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


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