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
 

 

to fetch unmatched rows from two tables

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Tue Oct 21, 2008 8:01 pm    Post subject: to fetch unmatched rows from two tables
Reply with quote

Hi,

I want to fetch unmatched rows from two tables. I have a common key which should not be equal.
In other words, I want all the rows other than those which I would get from an inner join on the common key.
Back to top
View user's profile Send private message

Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Tue Oct 21, 2008 8:14 pm    Post subject:
Reply with quote

Ex.

cost
prod-num cost seq-id
1 3 2
2 2 5
3 2 7
4 3 3

PRICE
prod-num price seq-id
1 1 2
2 2 4
3 3 6
4 4 3


Code:
SELECT * FROM COST A,PRICE B
WHERE A.PROD-NUM=B.PROD-NUM
  AND A.SEQ-ID =B.SEQ-ID


OUTPUT
prod-num cost seq-id prod-num price seq-id
1 3 2 1 1 2
4 3 3 4 4 3

my requirement is,

OUTPUT
prod-num cost seq-id prod-num price seq-id
--------------------------- 2 2 4
2 2 5 ---------------------------
--------------------------- 3 3 6
3 2 7 --------------------------
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Wed Oct 22, 2008 10:35 am    Post subject:
Reply with quote

I think my requirement will be satisfied by exceptional join or by coding a NOT EXISTS clause on second table.
Can someone put more light on these?
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 DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts Row-Numbers of distinct rows? Auryn DB2 1 Thu Oct 20, 2016 4:38 pm
No new posts Getting list of tables defined under ... kishpra DB2 2 Wed Aug 24, 2016 10:36 am
No new posts Multi row fetch - "for read only... Nileshkul DB2 3 Sun Aug 14, 2016 12:52 am


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