dbTalk Databases Forums  

Subquery not returning results

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Subquery not returning results in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Sashi
 
Posts: n/a

Default Subquery not returning results - 04-08-2009 , 10:05 AM






Hi All,

I have a simple subquery:

select ckt_id, charges
from table A
where ckt_id not in (select distinct ckt_id from B) and charges > 0

I know of at least one record in A whose ckt_id is not present in
table B and charges > 0 which is not being returned.

Table A has about 15000 records and B has about 50000 records.

What am I missing here?

Thanks in advance,
ZSashi

Reply With Quote
  #2  
Old   
ddf
 
Posts: n/a

Default Re: Subquery not returning results - 04-08-2009 , 10:48 AM






On Apr 8, 10:05*am, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi All,

I have a simple subquery:

select ckt_id, charges
from table A
where ckt_id not in (select distinct ckt_id from B) and charges > 0

I know of at least one record in A whose ckt_id is not present in
table B and charges > 0 which is not being returned.

Table A has about 15000 records and B has about 50000 records.

What am I missing here?

Thanks in advance,
ZSashi
We don't know because you haven't posted:

The Oracle release you're using
The DDL for the tables involved
Sample data for these tables

Provide the missing information and maybe someone can assist you.


David Fitzjarrell


Reply With Quote
  #3  
Old   
Mark D Powell
 
Posts: n/a

Default Re: Subquery not returning results - 04-08-2009 , 11:11 AM



On Apr 8, 11:05*am, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi All,

I have a simple subquery:

select ckt_id, charges
from table A
where ckt_id not in (select distinct ckt_id from B) and charges > 0

I know of at least one record in A whose ckt_id is not present in
table B and charges > 0 which is not being returned.

Table A has about 15000 records and B has about 50000 records.

What am I missing here?

Thanks in advance,
ZSashi
First I suggest you label the chk_id column in the subquery (b.chk_id)
to take it out of the scope of table A. Second a
"not in" is not exactly the opposite of an "in" clause so never use
one where a NULL can be returned.

HTH -- Mark D Powell --


Reply With Quote
  #4  
Old   
Michael Austin
 
Posts: n/a

Default Re: Subquery not returning results - 04-08-2009 , 01:15 PM



Sashi wrote:
Quote:
Hi All,

I have a simple subquery:

select ckt_id, charges
from table A
where ckt_id not in (select distinct ckt_id from B) and charges > 0

I know of at least one record in A whose ckt_id is not present in
table B and charges > 0 which is not being returned.

Table A has about 15000 records and B has about 50000 records.

What am I missing here?

Thanks in advance,
ZSashi

While Oracle does attempt to automatically give your column names an
alias, you need to get in the habit of using EXPLICIT names like:

select a.ckt_id, a.charges
from tablea A
where a.ckt_id not in (select distinct b.ckt_id from tableb B)
and a.charges > 0


Reply With Quote
  #5  
Old   
William Robertson
 
Posts: n/a

Default Re: Subquery not returning results - 04-10-2009 , 02:28 PM



On Apr 8, 4:05*pm, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi All,

I have a simple subquery:

select ckt_id, charges
from table A
where ckt_id not in (select distinct ckt_id from B) and charges > 0

I know of at least one record in A whose ckt_id is not present in
table B and charges > 0 which is not being returned.

Table A has about 15000 records and B has about 50000 records.

What am I missing here?

Thanks in advance,
ZSashi
Just to follow on from what Mark said about null values, try:

select ckt_id, charges
from table A
where ckt_id not in
( select b.ckt_id from b
where b.ckt_id is not null )
and charges > 0;

This is a bit of a guess in the absence of complete details, though.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.