Joining two queries in one query

Purchasing & Inventory forum can be used to discuss all features/issues related to Oracle Purchasing & Inventory.
Post Reply
AIMAM
Posts: 139
Joined: Thu May 17, 2007 6:04 am
Location: Egypt

Joining two queries in one query

Post by AIMAM »

Hello,

I have two queries from the table "mtl_onhand_quantities", that i need to represnt in the same report. Each query represents the same column but with different conditions.

The first query:

Code: Select all

(select INVENTORY_ITEM_ID,sum (TRANSACTION_QUANTITY) as "MAINWAREHOUSE QTY" 
 from mtl_onhand_quantities
 where
 ORGANIZATION_ID= 209
 AND SUBINVENTORY_CODE='MWarehouse'
 OR SUBINVENTORY_CODE = 'MWAREHOUSE'
 Group by 
 INVENTORY_ITEM_ID)   -- 30 record
The second query is:

(

Code: Select all

select INVENTORY_ITEM_ID,sum (TRANSACTION_QUANTITY) as "Business Centres QTY " 
 from mtl_onhand_quantities
 where
 ORGANIZATION_ID= 209
 AND SUBINVENTORY_CODE <>'MWarehouse'
 AND SUBINVENTORY_CODE <> 'MWAREHOUSE'
 Group by 
 INVENTORY_ITEM_ID)  -- 20 record
 
As you can see the number of records of each query is different from the other.

How can i join the two columns in one query, for reporting purposes?

Please help...
AIMAM
Posts: 139
Joined: Thu May 17, 2007 6:04 am
Location: Egypt

Post by AIMAM »

Thank you..

I found the following and it worked perfectly:

select INVENTORY_ITEM_ID
,sum(DECODE(UPPER(SUBINVENTORY_CODE),'MWAREHOUSE',TRANSACTION_QUANTITY)) as "MAINWAREHOUSE QTY"
,sum(DECODE(UPPER(SUBINVENTORY_CODE),'MWAREHOUSE',NULL, TRANSACTION_QUANTITY)) as "Business Centres QTY"
from mtl_onhand_quantities
where ORGANIZATION_ID= 209
Group by INVENTORY_ITEM_ID
admin
Posts: 2118
Joined: Fri Mar 31, 2006 12:59 am
Location: Pakistan
Contact:

Post by admin »

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests