View previous topic :: View next topic
|
Author |
Message |
abdulrafi
Active User
Joined: 14 Sep 2009 Posts: 184 Location: Coimbatore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Manish Prabhakar Gokhare
New User
Joined: 20 Aug 2011 Posts: 3 Location: INDIA
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
|
|