Home » SQL & PL/SQL » SQL & PL/SQL » comparing between two nested select statements
comparing between two nested select statements [message #4421] Fri, 06 December 2002 14:47 Go to next message
Bryan Wyka
Messages: 4
Registered: December 2002
Junior Member
I have a huge nested select statement. There is a piece that selects the sum from one table and subtracts it from another table. The problem comes to light when one of the table does not contain all of the same information that the other one does. Is there a way to make it link with out actually having the item exist. Below is the statement and some other notes.
select sku.item as item1
,(sku.oh - nvl(cu.qty,0)) as qty
from (
select sk.item, sum(sk.oh) oh from sku sk, loc
where sk.loc = loc.loc and
loc.descr2 = 'CONSUMER' and
sk.item = '080.0006586.003'
group by sk.item
)sku,
item i,
(/*this is the part that does not contain the above information*/
select cu.item, sum(cu.qty) qty from custorder cu, loc
where cu.loc = loc.loc and
loc.descr2 = 'CONSUMER' and
cu.item = '080.0006586.003'
group by cu.item
) cu
where sku.item =i.item and
sku.item = cu.item
if either of these nested statement are null then the entire statement fails.

Help please.
Re: comparing between two nested select statements [message #4422 is a reply to message #4421] Fri, 06 December 2002 16:01 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
You could just outer join to the cu inline view:

where sku.item =i.item
  and sku.item = cu.item (+);
Previous Topic: Reletionships
Next Topic: How to find Time zone.
Goto Forum:
  


Current Time: Thu May 16 06:22:43 CDT 2024