Joining two queries?
870374Aug 29 2011 — edited Aug 29 2011Hi,
I'm trying to 'join' two SQL queries:
*1) Lists all organizations*
SELECT org.organization_name, org.organization_id
FROM APPS.ORG_ORGANIZATION_DEFINITIONS ORG
order by ORG.ORGANIZATION_NAME
;
*2) Lists all categories without accounting entries in specific organization (id 87)*
SELECT CAT.CATEGORY_CONCAT_SEGS, CAT.*
FROM APPS.MTL_CATEGORIES_V CAT
WHERE CAT.ENABLED_FLAG = 'Y'
and CAT.DISABLE_DATE is null
AND CAT.STRUCTURE_NAME = 'PO Item Category'
AND CAT.CATEGORY_ID NOT IN (SELECT ACC.CATEGORY_ID
FROM APPS.MTL_CATEGORY_ACCOUNTS_V ACC
WHERE ACC.ORGANIZATION_ID = 87
)
order by CAT.CATEGORY_CONCAT_SEGS
;
Could you help in joining these two queries, as several ways that I've tired didn't bring me the expected results.
Table ORG_ORGANIZATION_DEFINITIONS has list of organizations with their IDs, e.g.
organization_id organization_name
87 GBP
101 USD
102 EUR
View MTL_CATEGORIES_V has list of categories, e.g.
CATEGORY_ID CATEGORY_CONCAT_SEGS
3485 Card Production
3491 Incentives
3490 Training
View MTL_CATEGORY_ACCOUNTS_V has list of accounts for specific category and specific account, e.g.
ORGANIZATION_ID CATEGORY_ID
3485 87
3491 87
3491 101
As per my sample data, I would expect these results:
ORGANIZATION_ID CATEGORY_ID CATEGORY_CONCAT_SEGS
87 3490 Training
101 3485 Card Production
101 3490 Training
102 3485 Card Production
102 3491 Incentives
102 3490 Training
Edited by: gytis on 2011.8.29 02.43