Domanda

I have a problem of joining the tables of Oracle r12 tables. I have tried something like this..

SELECT
     part.party_name,
     custA.account_number,
     headAll.cust_po_number,
     headAll.order_number,
     trans.NAME,
     headAll.ordered_date,
     sales.person_name,
     headAll.flow_status_code,
     items.segment1,
     lineAll.ordered_quantity,
     lineAll.order_quantity_uom,
     lineAll.unit_selling_price,
     lineAll.tax_code
FROM
     oe_order_headers_all headAll,
     oe_order_lines_all lineAll,
     hz_cust_accounts custA,
     hz_parties part,
     oe_transaction_types_tl trans,
     hz_person_profiles sales,
     mtl_system_items_b items
WHERE
     headAll.Header_ID       = lineAll.Header_ID
 AND custA.Application_ID    = part.Application_ID
 AND custA.Application_ID    = sales.Application_ID
 AND items.inventory_item_id = lineAll.inventory_item_id;

It is running but I know it is wrong because it is multiplying tables. Any Ideas of r12 tables in Oracle and combining this sample r12 tables?

-oe_order_headers_all 
-oe_order_lines_all
-hz_cust_accounts
-hz_parties
-oe_transaction_types_tl
-hz_person_profiles
-mtl_system_items_b

I Tried this..

Updated:

 from oe_order_headers_all headAll
 INNER JOIN
 oe_order_lines_all lineAll
 ON headAll.Header_ID = lineAll.Header_ID
 INNER JOIN
 hz_cust_accounts custA 
 ON headAll.sold_to_org_id = custA.cust_account_id
 INNER JOIN
 hz_parties part
 ON custA.party_id = part.party_id 
 INNER JOIN
 oe_transaction_types_tl trans
 ON headAll.order_type_id = trans.transaction_type_id
 INNER JOIN
 hz_person_profiles sales 
 ON part.party_id = sales.party_id
 INNER JOIN
 mtl_system_items_b items 
 ON items.inventory_item_id = lineAll.inventory_item_id

And I Tried Where Clause

 where headAll.Header_ID = lineAll.Header_ID AND headAll.order_type_id = trans.transaction_type_id  AND custA.party_id = part.party_id 
 AND part.party_id = sales.party_id AND headAll.sold_to_org_id = custA.cust_account_id AND items.inventory_item_id = lineAll.inventory_item_id;

Still multiplying..

È stato utile?

Soluzione

Forget about having Oracle R12 suite. In general any Oracle engine will behave like this. Let me show you some examples.

TABLE A
- COL1 PK1
- COL2 PK1
- COL3

TABLE B
- COL4 PK2
- COL5 PK2
- COL6

TABLE C
- COL7 
- COL8 -PK3
- COL9 -PK3

In this model, whenever we join any tables unless you join on their key combinations or based on the rule that for any given row you retrieve a maximum of one row from the other table.

SELECT A.COL1
FROM   TABLEA, TABLEB
WHERE  COL1 = COL4
AND    COL2 = COL5; 

OR in ANSI syntax

SELECT A.COL1
FROM   TABLEA 
JOIN TABLEB ON COL1 = COL4 AND COL2 = COL5; 

So this can be extended on the third table.

SELECT A.COL1
FROM   TABLEA, TABLEB, TABLEC
WHERE  COL1 = COL4
AND    COL2 = COL5
AND    COL1 = COL8
AND    COL2 = COL9; 

PS: The assumption is that the combined primary key on both the tables will always provide one row for the other.

You need to extend your ON clauses to include a condition so that for each entry in TABLE A there is only one entry in TABLE B that matches the condition and that for each entry in TABLE B there is only one entry in TABLE C

You can always try to join tables one by one and keep the query building until and unless you done violate the thumb rule (said above).

If, I change the join condition and any table duplicates while performing the same, then the same will be propagated to the subsequent joins.

Altri suggerimenti

There are not all relations between tables. Alias trans isn't related at all, groups headAll, lineAll, items and custA, part, sales are separated. In this case rows will be joined with default cross join.

Add conditions in the WHERE clause:

AND headAll.order_type_id = trans.transaction_type_id

AND headAll.sold_to_org_id = custA.cust_account_id

Please see this example from Oracle tutorial: Query to get the OM Sales Order summary details

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top