IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

comparing two tables


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
abdulrafi

Active User


Joined: 14 Sep 2009
Posts: 184
Location: Coimbatore

PostPosted: Wed Sep 21, 2011 11:53 pm
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

Moderator Emeritus


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

PostPosted: Thu Sep 22, 2011 12:55 am
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
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: 1281
Location: Belgium

PostPosted: Mon Oct 03, 2011 6:46 pm
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: 1281
Location: Belgium

PostPosted: Mon Oct 03, 2011 7:04 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Need to fetch data from so many DB2 t... DB2 9
No new posts Comparing Header and Trailer. DFSORT/ICETOOL 7
No new posts How to: PK does not exist in several ... DB2 6
No new posts Discrepancy b/w SYSIBM tables and BMC... DB2 0
No new posts SYSIBM Tables Query DB2 8
Search our Forums:

Back to Top