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
 

 

comparing two tables

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

Active User


Joined: 14 Sep 2009
Posts: 145
Location: Coimbatore

PostPosted: Wed Sep 21, 2011 11:53 pm    Post subject: comparing two tables
Reply with quote

Hi,

Could you please suggest me how this can be handled.

I have two DB2 tables , table A and table B. both has reg.no in it.
I need to find the reg.no found in table B which is not available in table A. I used the query,

select distinct reg_no from B b
where b.reg_no not in (select a.reg_no from A a)

I dint get proper output. most of reg.no are not coming in the output.
Could anybody suggest me a solution.
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Sep 22, 2011 12:55 am    Post subject:
Reply with quote

Hello,

Are you willing to write some code to do this?

Rather than one problematic query (that you have), you could use 2 queries. The first to read the B entries (distinct) and then read the A table using the reg_no. Either it is found or not and the code would act accordingly.

Another was would to be to create sequetial files of the entries in both tables and compare these with your sort product.

With the query you have, you might consider GROUP BY instead of distinct.

Quote:
I dint get proper output. most of reg.no are not coming in the output.
Saying it didn't work gives nothing to use to help you. Sayin "most are not coming" provides little. You need to post which ones are failing and determine why they fail.
Back to top
View user's profile Send private message
Manish Prabhakar Gokhare

New User


Joined: 20 Aug 2011
Posts: 3
Location: INDIA

PostPosted: Sat Oct 01, 2011 6:19 pm    Post subject:
Reply with quote

Use join : don't go for subquery

select B.reg_num from tableA A
JOIN tableB B

ON B.reg_no != A.reg_no with ur;
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1280
Location: Belgium

PostPosted: Mon Oct 03, 2011 6:46 pm    Post subject:
Reply with quote

Manish Prabhakar Gokhare wrote:
Use join : don't go for subquery

select B.reg_num from tableA A
JOIN tableB B

ON B.reg_no != A.reg_no with ur;
Total BS
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1280
Location: Belgium

PostPosted: Mon Oct 03, 2011 7:04 pm    Post subject:
Reply with quote

the query as descriped in Post 1 should fulfill the requirement desribed in Post 1.
alternatives are not exists and except :
Code:
select reg_no from tableB b
where b.reg_no not in (select a.reg_no from tableA a)

select reg_no from tableB b
where not exists (select 1 from tableA a where A.reg_no =BA.reg_no )

select reg_no from tableB b
except
select reg_no from tableA a
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 Data replication from multiple Db2 ta... kishpra DB2 5 Mon Mar 27, 2017 9:58 pm
No new posts SPUFI -- Joining 3 tables – data in... Sysaron DB2 2 Wed Mar 08, 2017 4:18 am
No new posts To know activities on db2 tables ashek15 DB2 4 Fri Mar 03, 2017 11:23 pm
No new posts ERM-Diagram of SysIBM-Catalog-Tables Auryn DB2 2 Fri Feb 17, 2017 6:22 pm
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am


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