outer join information
Dear expert;If you look at the section of outer join. The user asserts that there is no complete equivalent in the outer join syntax. Is it true.
http://www.Oracle-base.com/articles/9i/ANSIISOSQLSupport.php
If this is not the case, no one knows the equivalent. Thank you
It's true, but you can do something similar by using the UNION.
Example of
http://www.Oreillynet.com/network/2002/04/23/fulljoin.html
Concerning
Peter
Tags: Database
Similar Questions
-
Bug with an outer join, or &; Analytics function (or rownum)
Hello
Seems to be a combination of an outer join, OR and rownum confuses the CBO.
First request is without rownum, the second is with rownum.
The second query expects 203 t lines and never ends. It should behave the same as query 1, with 24 M lines.
Remove the GOLD clause query 2 allows him to behave as a query 1, with 24 M lines.
We never saw it? Is there a solution?
SELECT * FROM message i LEFT JOIN (SELECT hi.message_id, hi.update_dt FROM message_hist hi) h ON (t.id = h.master_id AND(t.update_dt = h.update_dt OR h.update_dt <TO_DATE('150901','RRMMDD'))); ----------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 24M| 13G| 475G (2)|999:59:59 | | 1 | NESTED LOOPS OUTER | | 24M| 13G| 475G (2)|999:59:59 | | 2 | TABLE ACCESS FULL | MESSAGE | 8037K| 1318M| 29883 (2)| 00:06:59 | | 3 | VIEW | | 3 | 1302 | 59136 (2)| 00:13:48 | |* 4 | TABLE ACCESS FULL| MESSAGE_HIST | 3 | 168 | 59136 (2)| 00:13:48 | ----------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("I"."MESSAGE_ID"="HI"."MESSAGE_ID" AND ("HI"."UPDATE_DT"<TO_DATE('150901','RRMMDD') OR "I"."UPDATE_DT"="HI"."UPDATE_DT")) ---------------- SELECT * FROM message i LEFT JOIN (SELECT hi.message_id, hi.update_dt , ROWNUM FROM message_hist hi) h ON (t.id = h.master_id AND(t.update_dt = h.update_dt OR h.update_dt <TO_DATE('150901','RRMMDD'))); ------------------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 203T| 112P| 475G (2)|999:59:59 | | 1 | NESTED LOOPS OUTER | | 203T| 112P| 475G (2)|999:59:59 | | 2 | TABLE ACCESS FULL | MESSAGE | 8037K| 1318M| 29883 (2)| 00:06:59 | | 3 | VIEW | | 25M| 10G| 59151 (2)| 00:13:49 | |* 4 | VIEW | | 25M| 10G| 59151 (2)| 00:13:49 | | 5 | COUNT | | | | | | | 6 | TABLE ACCESS FULL| MESSAGE_HIST | 25M| 1355M| 59151 (2)| 00:13:49 | ------------------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("I"."MESSAGE_ID"="H"."MESSAGE_ID" AND ("I"."UPDATE_DT"="H"."UPDATE_DT" OR "H"."UPDATE_DT"<TO_DATE('150901','RRMMDD')))
RowNum in a subquery is supposed to ensure that the subquery is evaluated completely before filtering, otherwise, how could you go out rownum?
Your question is compounded because of the join condition that forces a level of nested loops, which means that the table should be fully analysed once for each line of conduct rowsource. You can either transform the join in an equijoin and allow a hash to run, or you join could materialize the subquery once.
Allow the hash join:
SELECT count (*)
Message FROM
LEFT JOIN (SELECT hi.message_id, hi.update_dt
ROWNUM
OF message_hist salvation) PM ON (i.message_id = h.message_id
AND i.update_dt = h.update_dt)
LEFT JOIN (SELECT hi.message_id, hi.update_dt
ROWNUM
OF message_hist salvation) h2 ON (i.message_id = h2.message_id
AND h2.update_dt<>
AND h2.update_dt <> i.update_dt)
/
----------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 66. 211 (1) | 00:00:01 |
| 1. GLOBAL TRI | | 1. 66. | |
|* 2 | EXTERNAL RIGHT HASH JOIN | | 800 | 52800 | 211 (1) | 00:00:01 |
|* 3 | VIEW | | 1. 22. 70 (0) | 00:00:01 |
| 4. COUNTY | | | | | |
| 5. TABLE ACCESS FULL | MESSAGE_HIST | 1. 22. 70 (0) | 00:00:01 |
|* 6 | EXTERNAL RIGHT HASH JOIN | | 800 | 35200. 141 (1) | 00:00:01 |
| 7. VIEW | | 1. 22. 70 (0) | 00:00:01 |
| 8. COUNTY | | | | | |
| 9. TABLE ACCESS FULL | MESSAGE_HIST | 1. 22. 70 (0) | 00:00:01 |
| 10. TABLE ACCESS FULL | MESSAGE | 800 | 17600 | 70 (0) | 00:00:01 |
----------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
2 - access("I".") MESSAGE_ID '= 'H2'.' MESSAGE_ID "(+))"
filter ("H2". "UPDATE_DT" (+)<>'I'. " ("' UPDATE_DT")
3 - filter("H2".") UPDATE_DT "(+)<>
6 - access("I".") "UPDATE_DT" ="H" UPDATE_DT "(+) AND"
"I"." ' MESSAGE_ID ' ="H" MESSAGE_ID "(+))"
Materialize the subquery:
WITH h AS (SELECT / * + MATERIALIZE * / hi.message_id, hi.update_dt)
ROWNUM
OF message_hist salvation)
SELECT count (*)
Message FROM
LEFT JOIN: ON (i.message_id = h.message_id
AND (i.update_dt = h.update_dt OR h.update_dt<>
----------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 22. 1740 (0) | 00:00:01 |
| 1. TRANSFORMATION OF THE TEMPORARY TABLE. | | | | |
| 2. LOAD SELECT ACE | SYS_TEMP_0FD9D6810_5B8F6E67 | | | | |
| 3. COUNT | | | | | |
| 4. TABLE ACCESS FULL | MESSAGE_HIST | 1. 22. 70 (0) | 00:00:01 |
| 5. GLOBAL TRI | | 1. 22. | |
| 6. NESTED EXTERNAL LOOPS | | 800 | 17600 | 1670 (0) | 00:00:01 |
| 7. TABLE ACCESS FULL | MESSAGE | 800 | 17600 | 70 (0) | 00:00:01 |
| 8. VIEW | | 1. | 2 (0) | 00:00:01 |
|* 9 | VIEW | | 1. 22. 2 (0) | 00:00:01 |
| 10. TABLE ACCESS FULL | SYS_TEMP_0FD9D6810_5B8F6E67 | 1. 22. 2 (0) | 00:00:01 |
----------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
9 - filter("I".") ' MESSAGE_ID ' ="H" MESSAGE_ID' AND ('I'. "" "UPDATE_DT"="H" UPDATE_DT' OR
"H"." UPDATE_DT ".<>
You may need to change the first condition to make sure that you select the correct subquery.
-edit
Not able to view a plan but you can invade the second join condition select and then the result of a subquery with a predicate according to your requirement. This should delay the or rating and leave only an equijoin (although rowsource return may be slightly larger than the opposite).
-Second edition, it did not work exactly when I tried it.
A hybrid of the previous two plans with a slight modification of how he was imitating the GOLD:
WITH h AS (SELECT / * + MATERIALIZE * / hi.message_id, hi.update_dt)
ROWNUM Clotilde
OF message_hist salvation)
SELECT i.MESSAGE_ID
i.UPDATE_DT
COALESCE(h.message_id,h2.message_id) message_id
, COALESCE (h.update_dt, h2.update_dt) update_dt
Clotilde COALESCE (h.rown, h2.rown)
Message FROM
LEFT JOIN: ON (i.message_id = h.message_id
AND i.update_dt = h.update_dt)
LEFT JOIN: h2 WE (DECODE(h.message_id,,i.message_id) = h2.message_id - only try this if previous join returned NULL
AND h2.update_dt<>
/
--------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 66. 8 (0) | 00:00:01 |
| 1. TRANSFORMATION OF THE TEMPORARY TABLE. | | | | |
| 2. LOAD SELECT ACE | SYS_TEMP_0FD9D6605_28F27F | | | | |
| 3. COUNT | | | | | |
| 4. TABLE ACCESS FULL | MESSAGE_HIST | 150. 3300 | 2 (0) | 00:00:01 |
| 5. GLOBAL TRI | | 1. 66. | |
|* 6 | EXTERNAL RIGHT HASH JOIN | | 10497. 676K | 6 (0). 00:00:01 |
|* 7 | VIEW | | 150. 3300 | 2 (0) | 00:00:01 |
| 8. TABLE ACCESS FULL | SYS_TEMP_0FD9D6605_28F27F | 150. 3300 | 2 (0) | 00:00:01 |
|* 9 | OUTER HASH JOIN | | 328. 14432 | 4 (0) | 00:00:01 |
| 10. TABLE ACCESS FULL | MESSAGE | 200 | 4400 | 2 (0) | 00:00:01 |
| 11. VIEW | | 150. 3300 | 2 (0) | 00:00:01 |
| 12. TABLE ACCESS FULL | SYS_TEMP_0FD9D6605_28F27F | 150. 3300 | 2 (0) | 00:00:01 |
--------------------------------------------------------------------------------------------------------Information of predicates (identified by the operation identity card):
---------------------------------------------------6 - access("H2".") MESSAGE_ID "(+) = DECODE (TO_CHAR ('H'". "))" MESSAGE_ID"), NULL, 'I '. (("' MESSAGE_ID '))
7 - filter("H2".") UPDATE_DT "(+)<>
9 - access("I".") "UPDATE_DT" ="H" UPDATE_DT "(+) AND 'I'." "" ' MESSAGE_ID '="H" MESSAGE_ID "(+))"(This plan is another system if costs are not comparable)
-
Hello
I have a requirement in which I need to get data from a third table where a date of the third table is higher than a date in the second array.
Ex:
SELECT t1.column1, t3.column2 FROM t1, t2, t3 WHERE t1.id = t2.foreign_id AND t1.id ( + ) = t3.foreign_id AND t3.some_date_column > t2.another_date_column
However, using the query above returns no results if the date condition is not met. I still need to show t1.column1 and a null t3.column2.
How should I do this?
Thank you
Allen
Edit: Added information about the requirement.
Hi Allen
- SELECT t1.column1, t3.column2
- T1, t2, t3
- WHERE t1.id = t2.foreign_id
- AND t1.id = t3.foreign_id (+)
- AND t3.some_date_column (+) > t2.another_date_column
I guess that this t1.column1 must not be null. Or am I wrong? The + sign must be placed on the side where draws are accepted. You must repeat it for each condition on the table.
Alternativlely you can use the LEFT OUT JOIN syntax. If the two columns are allowed null you need a FULL OUTER JOIN.
BTW: The join to t2 is not required if a refefernce constraint forced.
-
outer join when there are several tables are involved
Could not put up the question correctly to the last channel, my problem is with the join when there are several tables are involved, this is just one example of the task that I have to carry.
Tab1 aura model id retailer_id information for all the weeks (from the first Monday) of the month of JUNE with cost and Helen
Tab1
model_id
retailer_id
sell_date
cost
Helene
1
12
June 3, 13
100
40
1
12
June 10, 13
200
20
1
12
17 June 13
300
20
1
12
24 June 13
400
20
2
12
June 3, 13
300
10
2
12
June 10, 13
200
20
2
12
17 June 13
300
20
2
12
24 June 13
400
20
Tab2:
each retailer belongs to a dealer, under the table has the same information
retailer_id
Dealer_id
12
100
13
100
14
101
15
101
16
101
Tab 3
There is a third layer where each dealership is having a garage band
Dealer_id
Dealer_group
100
1001
101
1001
102
2001
103
2001
104
3001
105
3001
Tab4:
Of this table for each model and dealer discount information for the month of June (every week)
model_id
Dealer_group
discount_date
discount
1
1001
June 3, 13
10
1
1001
June 10, 13
20
1
1001
17 June 13
10
1
1001
24 June 13
30
2
1001
June 3, 13
10
2
1001
June 10, 13
20
2
1001
17 June 13
10
2
1001
24 June 13
30
3
2001
June 3, 13
10
3
2001
June 10, 13
20
3
2001
17 June 13
10
3
2001
24 June 13
30
Master_info:
It's the main table which is the master table for model /retailer information
Model_id
retailer_id
1
12
2
12
3
12
4
12
1
13
2
13
Output
model_id
retailer_id
sell_date
cost
Helene
Final (cost-helene-discount)
1
12
June 3, 13
100
40
50
1
12
June 10, 13
200
20
160
1
12
17 June 13
300
20
270
1
12
24 June 13
400
20
350
2
12
June 3, 13
300
10
280
2
12
June 10, 13
200
20
160
2
12
17 June 13
300
20
270
2
12
24 June 13
400
20
350
3
12
June 3, 13
0
0
0
3
12
June 10, 13
0
0
0
3
12
17 June 13
0
0
0
3
12
24 June 13
0
0
0
4
12
June 3, 13
0
0
0
4
12
June 10, 13
0
0
0
4
12
17 June 13
0
0
0
4
12
24 June 13
0
0
0
1
13
June 3, 13
0
0
0
1
13
June 10, 13
0
0
0
1
13
17 June 13
0
0
0
1
13
24 June 13
0
0
0
2
13
June 3, 13
0
0
0
2
13
June 10, 13
0
0
0
2
13
17 June 13
0
0
0
1
13
24 June 13
0
0
0
For highted above records (model_id / retailer_id combination) there is no record in tab1 but they have entered in master_info then the recordings should come for all model_id/retailer_id with all the 0 values
Hello
Thanks for posting the sample data.
It is unclear what dates you want to include in the output. The following query shows how you can generate every Monday in a given range. If you only want to include the dates that are actually present in tabl1 and/or tab4, you can simplify this a bit.
WITH date_range AS
(
SELECT TRUNC (TO_DATE (' 3 June 2013', 'DD-Mon-YYYY'))
, 'IW '.
) AS first_monday
, TRUNC (TO_DATE (24 June 2013 ', 'DD-Mon-YYYY') + 6)
, 'IW '.
) AS last_monday
OF the double
)
all_mondays AS
(
First_monday SELECT + (7 * (LEVEL - 1)) AS sell_date
OF date_range
CONNECT BY LEVEL<= 1="" +="" (="" (last_monday="" -="">=>
/ 7
)
)
SELECT mi.model_id
mi.retailer_id
am.sell_date
, Cost of NVL (t1.cost, 0) AS
, NVL (t1.rebat, 0) IN the refund
, NVL (t1.cost, 0)
-(NVL (t1.rebat, 0))
+ NVL (t4.discount, 0)
) AS final
E master_info
CROSS JOIN all_mondays am
LEFT OUTER JOIN tab1 t1 ON t1.model_id = mi.model_id
AND t1.retailer_id = mi.retailer_id
AND t1.sell_date = am.sell_date
LEFT OUTER JOIN tab2 t2 ON t2.retailer_id = mi.retailer_id
LEFT OUTER JOIN tab 3 t3 ON t3.dealer_id = t2.dealer_id
LEFT OUTER JOIN tab4 t4 ON t4.model_id = t1.model_id
AND t4.dealer_group = t3.dealer_group
AND t4.discount_date = t1.sell_date
ORDER BY mi.retailer_id
mi.model_id
am.sell_date
;
The results are not exactly what said you you wanted. I suspect it's because of typos in that you posted.
-
Problem with the implementation of Outer JOIN
Hello Guru,
Here's my scenario. I know that this can be achieved in several ways. But I need this in a single in aid Of JOINS EXTERNALrequest.
I have two tables namely masters and transactions table. I need to join two columns (trx_name, trx_type) of the two tables and the need for all transactions. Part the trickiest is off 2 join columns, one column can be NULL in the main table.
Script TABLES:
create master table (mstr_no number, trx_name varchar2 (100), trx_type varchar2 (100), trx_module varchar2 (100));
insert into masters values (1, 'yyyy', 'simple', 'cont');
insert into masters values (2, 'bbbb', < NULL >, "cust");
insert into masters values (3, 'yyyy', 'triple', "cont1");
create table transaction (trx_no number, trx_name varchar2 (100), trx_type varchar2 (100));
Insert in transaction values (1, 'yyyy', 'simple');
Insert the transaction values (2, 'bbbb', 'double');
Insert in transaction values (3, 'yyyy', 'triple');
Insert in transaction values (4, 'cccc', 'purple');
commit;
I need output like below.
1, 'yyyy', 'simple', 'cont '.
2, 'bbbb', < NULL >, * "cust."
3, 'yyyy', 'triple', "cont1".
4, 'cccc', 'purple', < NULL >
I need to join trx_name & trx_type in the two tables. Even if one of the column is null in the main table (mstr_no = 2), I have need of the corresponding value of trx_module since trx_name made match.
My query:
Select a.*, b.trx_module of transaction a, master b
where a.trx_name = b.trx_name (+)
and a.trx_type = NVL (b.trx_type (+), 'NULL')
order of a.trx_no
Appreciate your help.
Concerning
MNMaybe I'm wrong, but I don't think you can do this with a single outer join:
with full_matches as ( select * from master where trx_type is not null) , partial_matches as ( select * from master where trx_type is null) select a.* , coalesce(b.trx_module, c.trx_module) trx_module from transaction a left outer join full_matches b on (a.trx_name = b.trx_name and a.trx_type = b.trx_type) left outer join partial_matches c on (a.trx_name = c.trx_name) ; TRX_NO TRX_NAME TRX_TYPE TRX_MODULE ------ -------------------- -------------------- ------------ 1 aaaa single cont 3 aaaa triple cont1 2 bbbb double cust 4 cccc purple
Re-reading my answer, I see that a short explanation might be useful: the query uses two outer joins: first masters lines with the name and type are joined, and then type the lines with missing. Him coalesce work to choose the most relevant information of module.
Published by: Martin Preiss on June 7, 2013 20:24
-
Performance of outer join problem
Dear all,
Please help me in the development the sub query as it is particularly the outer join and goes for full scan of the table.
Query:
SELECT
T27. CONFLICT_ID,
T27. LAST_UPD,
T27. CREATED,
T27. LAST_UPD_BY,
T27. CREATED_BY,
T27. MODIFICATION_NUM,
T27. ROW_ID,
T24. ATTRIB_39,
T27. REMIT_ADDR_ORG_ID,
T27. REMIT_ORG_EXT_ID,
T16.NAME,
T25. ACCNT_TYPE_CD,
T27. RECAL_TAX_SRV_FLG,
T27. PROJ_ID,
T8. PROJ_NUM,
T8. BU_ID,
T5.NAME,
T8. INTEGRATION_ID,
T12. CURCY_CD,
T25. PR_BL_ADDR_ID,
T25. URL,
T27. TTL_INVC_AMT,
T27. INVC_TYPE_CD,
T27. TTL_PD_AMT,
T3. CG_ASSSET_ID,
T17. ASSET_NUM,
T27. VENDR_INVOICE_NUM,
T4. TOT_QTY_SHIP,
T4. TOT_EXTND_PRICE,
T27. ACCNT_ID,
T25. INTEGRATION_ID,
T25.NAME,
T25. BU_ID,
T25. AVAIL_CREDIT_AMT,
T10.NAME,
T27. AGREEMENT_ID,
T4. TOT_EXTND_TAX,
T27. STMT_SOURCE_CD,
T4. SRC_INVLOC_ID,
T27. STATUS_CD,
T4. TOT_QTY_BONUS,
T27. X_DEPOSIT_AMT,
T27.COMMENTS,
T27. INVC_FULLY_PAID_DT,
T26. SEQ_NUM,
T27. ELEMENT_ID,
T26. INSCLM_ID,
T14. INSCLAIM_NUM,
T27. BL_PER_ID,
T27. INS_CLAIM_ID,
T27. FN_ACCNT_ID,
T27. CUSTOMER_REF_NUM,
T27. TTL_NONREC_AMT,
T25. OU_NUM,
T24. ATTRIB_39,
T27. AMT_CURCY_CD,
T2. CCNUM_ENCRPKEY_REF,
T18. PR_DEPOSIT_ID,
T19. DISCNT_RULE_CD,
T27. ORDER_ID,
T4. STATUS_CHG_FLG,
T25. MAIN_PH_NUM,
T25. MAIN_FAX_PH_NUM,
T27. DELINQUENT_FLG,
T15. OPENING OF SESSION
T25. PR_POSTN_ID,
T4. ORDER_NUM,
T22. ADDR,
T22. Zip code
T27. INVC_NUM,
T27. INVC_DT,
T22. COUNTRIES,
T22. CITY,
T27. BL_ADDR_ID,
T23.NAME,
T27. POSTED_DT,
T20.NAME,
T27. BL_PERIOD_ID,
T27. GOODS_DLVRD_TS,
T23.NET_DAYS,
T27. PAYMENT_TERM_ID,
T23. DUE_DT,
T27. DUE_DT,
T27. VOID_REASON_TEXT,
T27. DEPT_CD,
T24. ATTRIB_60,
T24. ATTRIB_28,
T21. AMT,
T1. STATE,
T1. ADDR,
T1. ADDR_LINE_2,
T1. COUNTRIES,
T1. CITY,
T1. Zip code
T11. OPENING OF SESSION
T21. ROW_ID,
T9. ROW_ID,
T1. ROW_ID,
T13. ROW_ID,
T7. ROW_ID
Of
SIEBEL. S_ADDR_PER T1,
SIEBEL. S_PTY_PAY_PRFL T2,
SIEBEL. S_INVLOC T3,
SIEBEL. S_ORDER T4,
SIEBEL. S_ORG_EXT T5,
SIEBEL. S_POSTN T6,
SIEBEL. S_PARTY T7,
SIEBEL. S_PROJ T8,
SIEBEL. S_CON_ADDR T9,
SIEBEL. S_ORG_EXT T10,
SIEBEL. S_USER T11,
SIEBEL. S_DOC_QUOTE T12,
SIEBEL. S_ACCNT_POSTN T13,
SIEBEL. S_INS_CLAIM T14,
SIEBEL. S_USER T15,
SIEBEL. S_ORG_EXT T16,
SIEBEL. T17 S_ASSET,
SIEBEL. S_ORDER_TNTX T18,
SIEBEL. S_ORG_EXT_TNTX T19,
SIEBEL. S_PERIOD T20,
SIEBEL. S_DEPOSIT_TNT T21,
SIEBEL. T22 S_ADDR_PER,
SIEBEL. T23 S_PAYMENT_TERM,
SIEBEL. S_ORG_EXT_X T24,
SIEBEL. S_ORG_EXT T25,
SIEBEL. S_INSCLM_ELMNT T26,
SIEBEL. S_INVOICE T27
WHERE
T25. BU_ID = T10. PAR_ROW_ID (+) AND
T26. INSCLM_ID = T14. ROW_ID (+) AND
T27. ELEMENT_ID = T26. ROW_ID (+) AND
T27. LAST_UPD_BY = T15. PAR_ROW_ID (+) AND
T4. QUOTE_ID = T12. ROW_ID (+) AND
T3. CG_ASSSET_ID = T17. ROW_ID (+) AND
T27. BL_ADDR_ID = T22. ROW_ID (+) AND
T8. BU_ID = T5. PAR_ROW_ID (+) AND
T27. PER_PAY_PRFL_ID = T2. ROW_ID (+) AND
T27. REMIT_ORG_EXT_ID = T16. PAR_ROW_ID (+) AND
T27. PROJ_ID = T8. ROW_ID (+) AND
T27. BL_PERIOD_ID = T20. ROW_ID (+) AND
T27. PAYMENT_TERM_ID = T23. ROW_ID (+) AND
T12. BU_ID = T19. PAR_ROW_ID (+) AND
T27. ACCNT_ID = T25. PAR_ROW_ID (+) AND
T27. ORDER_ID = T18. ROW_ID (+) AND
T4. SRC_INVLOC_ID = T3. ROW_ID (+) AND
T27. ORDER_ID = T4. ROW_ID (+) AND
T27. ACCNT_ID = T24. PAR_ROW_ID (+) AND
T18. PR_DEPOSIT_ID = T21. ROW_ID (+) AND
T27. BL_ADDR_ID = T9. ADDR_PER_ID (+) AND
T27. ACCNT_ID = T9. ACCNT_ID (+) AND
T27. BL_ADDR_ID = T1. ROW_ID (+) AND
T25. PR_POSTN_ID = T13. POSITION_ID (+) AND
T25. ROW_ID = T13. OU_EXT_ID (+) AND
T13. POSITION_ID = T7. ROW_ID (+) AND
T13. POSITION_ID = T6. PAR_ROW_ID (+) AND
T6. PR_EMP_ID = T11. PAR_ROW_ID (+) AND
(T27. INVC_TYPE_CD =: 1) AND
(T27. DEPT_CD =: 2);
Explan exit Plan:
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hash value of plan: 3132260827
---------------------------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
---------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | 1. 1958 | 1896K (11) | 00:50:46 |
| 1. NESTED EXTERNAL LOOPS | 1. 1958 | 1896K (11) | 00:50:46 |
| 2. NESTED EXTERNAL LOOPS | 1. 1922 | 1896K (11) | 00:50:46 |
| 3. NESTED EXTERNAL LOOPS | 1. 1885 | 1896K (11) | 00:50:46 |
| 4. NESTED EXTERNAL LOOPS | 1. 1861. 1896K (11) | 00:50:46 |
| 5. NESTED EXTERNAL LOOPS | 1. 1849. 1896K (11) | 00:50:46 |
| 6. NESTED EXTERNAL LOOPS | 1. 1817 | 1896K (11) | 00:50:46 |
| 7. NESTED EXTERNAL LOOPS | 1. 1792 | 1896K (11) | 00:50:46 |
| 8. NESTED EXTERNAL LOOPS | 1. 1771. 1896K (11) | 00:50:46 |
| 9. NESTED EXTERNAL LOOPS | 1. 1739. 1896K (11) | 00:50:46 |
| 10. NESTED EXTERNAL LOOPS | 1. 1483. 1896K (11) | 00:50:46 |
| 11. NESTED EXTERNAL LOOPS | 1. 1451. 1896K (11) | 00:50:46 |
| 12. NESTED EXTERNAL LOOPS | 1. 1419. 1896K (11) | 00:50:46 |
| 13. NESTED EXTERNAL LOOPS | 1. 1361. 1896K (11) | 00:50:46 |
| 14. NESTED EXTERNAL LOOPS | 1. 1276 | 1896K (11) | 00:50:46 |
| 15. NESTED EXTERNAL LOOPS | 1. 1202 | 1896K (11) | 00:50:46 |
| 16. NESTED EXTERNAL LOOPS | 1. 1108 | 1896K (11) | 00:50:46 |
| 17. NESTED EXTERNAL LOOPS | 1. 1087 | 1896K (11) | 00:50:46 |
| 18. NESTED EXTERNAL LOOPS | 1. 1040 | 1896K (11) | 00:50:46 |
| 19. NESTED EXTERNAL LOOPS | 1. 939 | 1896K (11) | 00:50:46 |
| 20. NESTED EXTERNAL LOOPS | 1. 894. 1896K (11) | 00:50:46 |
| 21. NESTED EXTERNAL LOOPS | 1. 868. 1896K (11) | 00:50:46 |
| 22. NESTED EXTERNAL LOOPS | 1. 843. 1896K (11) | 00:50:46 |
| 23. NESTED EXTERNAL LOOPS | 1. 824. 1896K (11) | 00:50:46 |
| 24. NESTED EXTERNAL LOOPS | 1. 690. 1896K (11) | 00:50:46 |
| 25. NESTED EXTERNAL LOOPS | 1. 613. 1896K (11) | 00:50:46 |
| 26. NESTED EXTERNAL LOOPS | 1. 457. 1896K (11) | 00:50:46 |
| * 27. TABLE ACCESS FULL | S_INVOICE | 1. 269. 1896K (11) | 00:50:46 |
| 28. TABLE ACCESS BY INDEX ROWID | S_PROJ | 1. 188. 1 (0) | 00:00:01 |
| * 29. INDEX UNIQUE SCAN | S_PROJ_P1 | 1 | | 1 (0) | 00:00:01 |
| 30. TABLE ACCESS BY INDEX ROWID | S_PAYMENT_TERM | 1. 156. 1 (0) | 00:00:01 |
| * 31. INDEX UNIQUE SCAN | S_PAYMENT_TERM_P1 | 1 | | 1 (0) | 00:00:01 |
| 32. TABLE ACCESS BY INDEX ROWID | S_INSCLM_ELMNT | 1. 77. 1 (0) | 00:00:01 |
| * 33 | INDEX UNIQUE SCAN | S_INSCLM_ELMNT_P1 | 1 | | 1 (0) | 00:00:01 |
| 34. TABLE ACCESS BY INDEX ROWID | S_INS_CLAIM | 1. 134. 1 (0) | 00:00:01 |
| * 35 | INDEX UNIQUE SCAN | S_INS_CLAIM_P1 | 1 | | 1 (0) | 00:00:01 |
| 36. TABLE ACCESS BY INDEX ROWID | S_PERIOD | 1. 19. 1 (0) | 00:00:01 |
| * 37 | INDEX UNIQUE SCAN | S_PERIOD_P1 | 1 | | 1 (0) | 00:00:01 |
| 38. TABLE ACCESS BY INDEX ROWID | S_USER | 1. 25. 2 (0) | 00:00:01 |
| * 39 | INDEX UNIQUE SCAN | S_USER_U2 | 1 | | 1 (0) | 00:00:01 |
| 40. TABLE ACCESS BY INDEX ROWID | S_ORDER_TNTX | 1. 26. 2 (0) | 00:00:01 |
| * 41. INDEX UNIQUE SCAN | S_ORDER_TNTX_P1 | 1 | | 1 (0) | 00:00:01 |
| 42. TABLE ACCESS BY INDEX ROWID | S_DEPOSIT_TNT | 1. 45. 1 (0) | 00:00:01 |
| * 43. INDEX UNIQUE SCAN | S_DEPOSIT_TNT_P1 | 1 | | 1 (0) | 00:00:01 |
| 44. TABLE ACCESS BY INDEX ROWID | S_ORDER | 1. 101 | 2 (0) | 00:00:01 |
| * 45 | INDEX UNIQUE SCAN | S_ORDER_P1 | 1 | | 1 (0) | 00:00:01 |
| 46. TABLE ACCESS BY INDEX ROWID | S_INVLOC | 1. 47. 1 (0) | 00:00:01 |
| * 47 | INDEX UNIQUE SCAN | S_INVLOC_P1 | 1 | | 1 (0) | 00:00:01 |
| 48. TABLE ACCESS BY INDEX ROWID | S_DOC_QUOTE | 1. 21. 1 (0) | 00:00:01 |
| * 49 | INDEX UNIQUE SCAN | S_DOC_QUOTE_P1 | 1 | | 1 (0) | 00:00:01 |
| 50. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT_TNTX | 1. 94. 1 (0) | 00:00:01 |
| * 51 | INDEX RANGE SCAN | S_ORG_EXT_TNTX_U1 | 1 | | 1 (0) | 00:00:01 |
| 52. TABLE ACCESS BY INDEX ROWID | S_PTY_PAY_PRFL | 1. 74. 1 (0) | 00:00:01 |
| * 53 | INDEX UNIQUE SCAN | S_PTY_PAY_PRFL_P1 | 1 | | 1 (0) | 00:00:01 |
| 54. TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1. 85. 2 (0) | 00:00:01 |
| * 55 | INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | 1 (0) | 00:00:01 |
| 56. TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1. 58. 1 (0) | 00:00:01 |
| * 57 | INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | 1 (0) | 00:00:01 |
| 58. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1. 32. 1 (0) | 00:00:01 |
| * 59 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0) | 00:00:01 |
| 60. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1. 32. 1 (0) | 00:00:01 |
| * 61. INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0) | 00:00:01 |
| 62. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1. 256. 2 (0) | 00:00:01 |
| * 63. INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0) | 00:00:01 |
| 64. TABLE ACCESS BY INDEX ROWID | S_ACCNT_POSTN | 1. 32. 3 (0) | 00:00:01 |
| * 65 | INDEX RANGE SCAN | S_ACCNT_POSTN_U1 | 1 | | 2 (0) | 00:00:01 |
| 66. TABLE ACCESS BY INDEX ROWID | S_POSTN | 1. 21. 1 (0) | 00:00:01 |
| * 67. INDEX UNIQUE SCAN | S_POSTN_U2 | 1 | | 1 (0) | 00:00:01 |
| 68. TABLE ACCESS BY INDEX ROWID | S_USER | 1. 25. 2 (0) | 00:00:01 |
| * 69 | INDEX UNIQUE SCAN | S_USER_U2 | 1 | | 1 (0) | 00:00:01 |
| 70. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1. 32. 2 (0) | 00:00:01 |
| * 71 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0) | 00:00:01 |
| * 72 | INDEX UNIQUE SCAN | S_PARTY_P1 | 1. 12. 1 (0) | 00:00:01 |
| 73. TABLE ACCESS BY INDEX ROWID | S_ASSET | 1. 24. 2 (0) | 00:00:01 |
| * 74 | INDEX UNIQUE SCAN | S_ASSET_P1 | 1 | | 2 (0) | 00:00:01 |
| 75. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT_X | 1. 37. 2 (0) | 00:00:01 |
| * 76 | INDEX RANGE SCAN | S_ORG_EXT_X_U1 | 1 | | 2 (0) | 00:00:01 |
| 77. TABLE ACCESS BY INDEX ROWID | S_CON_ADDR | 1. 36. 3 (0) | 00:00:01 |
| * 78 | INDEX RANGE SCAN | S_CON_ADDR_U1 | 1 | | 2 (0) | 00:00:01 |
---------------------------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
27 - filter("T27".") DEPT_CD "=: 2 AND"T27"". "" INVC_TYPE_CD "(=:1)"
29 - access("T27".") PROJ_ID '= 'T8'.' ROW_ID "(+))"
31 - access("T27".") PAYMENT_TERM_ID "="T23"." ROW_ID "(+))"
33 - access("T27".") ELEMENT_ID "="T26"." ROW_ID "(+))"
35 - access("T26".") INSCLM_ID "="T14"." ROW_ID "(+))"
37 - access("T27".") BL_PERIOD_ID '= 'T20'.' ROW_ID "(+))"
39 - access("T27".") LAST_UPD_BY "="T15"." PAR_ROW_ID "(+))"
41 - access("T27".") ORDER_ID "="T18"." ROW_ID "(+))"
43 - access("T18".") PR_DEPOSIT_ID "="T21"." ROW_ID "(+))"
45 - access("T27".") ORDER_ID "="T4"." ROW_ID "(+))"
47 - access("T4".") SRC_INVLOC_ID '= 'T3'.' ROW_ID "(+))"
49 - access("T4".") QUOTE_ID "="T12"." ROW_ID "(+))"
51 - access("T12".") BU_ID "="T19"." PAR_ROW_ID "(+))"
53 - access("T27".") PER_PAY_PRFL_ID '= 'T2'.' ROW_ID "(+))"
55 - access("T27".") BL_ADDR_ID '= 'T1'.' ROW_ID "(+))"
57 - access("T27".") BL_ADDR_ID '= 'T22'.' ROW_ID "(+))"
59 - access("T8".") BU_ID '= 'T5'.' PAR_ROW_ID "(+))"
61 - access("T27".") REMIT_ORG_EXT_ID '= 'T16'.' PAR_ROW_ID "(+))"
63 - access("T27".") ACCNT_ID '= 'T25'.' PAR_ROW_ID "(+))"
65 - access("T25".") ROW_ID "= 'T13'." OU_EXT_ID "(+) AND 'T25'." ' PR_POSTN_ID '= "T13". "POSITION_ID" (+)) "
67 - access("T13".") POSITION_ID "="T6"." PAR_ROW_ID "(+))"
69 - access("T6".") PR_EMP_ID '= 'T11'.' PAR_ROW_ID "(+))"
71 - access("T25".") BU_ID '= 'T10'.' PAR_ROW_ID "(+))"
72 - access("T13".") POSITION_ID '= 'T7'.' ROW_ID "(+))"
74 - access("T3".") CG_ASSSET_ID "="T17"." ROW_ID "(+))"
76 - access("T27".") ACCNT_ID '= 'T24'.' PAR_ROW_ID "(+))"
78 - access("T27".") BL_ADDR_ID "="T9"." ADDR_PER_ID "(+) AND 'T27'." "ACCNT_ID"= "T9". "ACCNT_ID" (+)) "
filter ("T27". "ACCNT_ID"= "T9"." ACCNT_ID "(+))"
117 selected lines.
We use 10.2.0.3 oracle version.Hello
According to the plan of the explain command, > 99% of the cost of the query comes from a single operation - step 27, a comprehensive analysis of the S_INVOICE table.
This probably means that there is no index can be used on DEPT_CD and/or INVC_TYPE_CD.So start by setting SELECT * FROM S_INVOICE WHERE ("T27" T27. "DEPT_CD" =: 2 AND "T27" "." " INVC_TYPE_CD "(=:1)"
BTW the plan shows that the 1 row should be returned, while Oracle actually returns 117 - this means that the optimizer estimates are not very reliable here.
Best regards
Nikolai -
Outer join problem? test code included
Hi all
I have three tables:
Master: It's the program_codes, titles and the active indicator.
Main: Is the 'information sections"on a specific program.
ModeOfS: He intones the sections of main program (abstract e.t.c) full-time part-time (PT) or (FT).
They have all of the effective dates so when he ran during a given year knows whose registration was effective on this year here.
When I run for 2003 I get 4 records which is correct, but when I run for 2002, I have only 2 folders. There is no valid records in the 'ModeOfS' table, but there are three records in the table of the 'hand' that are valid. But missing registration of P1 of the table of the 'hand '.
I have external-joined the main table so I don't see why it doesn't show up. Any help would be great.
Basically, program information may be considered at the level of "ModeOfS" but should not be, it's that his different text. So if it does and it is in the selected year then I want to see it. The limits of two YEARS will always be the same thing that this query will run for one YEARHello
oraCraft wrote:
Hi allI have three tables:
Master: It's the program_codes, titles and the active indicator.
Main: Is the 'information sections"on a specific program.
ModeOfS: He intones the sections of main program (abstract e.t.c) full-time part-time (PT) or (FT).They have all application dates
I'm confused. In the sample data you posted, it seems that only 2 tables have dates of application. Did you post erroneous data, at least for the master by mistake?
so when he ran during a given year knows whose registration was effective on this year here.
When I run for 2003 I get 4 records which is correct, but when I run for 2002, I have only 2 folders. There is no valid records in the 'ModeOfS' table, but there are three records in the table of the 'hand' that are valid. But missing registration of P1 of the table of the 'hand '.What are the correct results for 2002? They are:
PROG TITLE A ID PROG TERM_EFF SECTION TEXT FK MO TERM_EFF SECTION TEXT ---- ------------- - -- ---- ---------- ------------ ----------------------- -- -- ---------- -------- ------------------- 0862 Mechanics Y P1 0862 2000 ABSTRACT This is Data 0862 Mechanics Y P2 0862 2000 OBJECTIVE This is Data 0862 Mechanics Y P3 0862 2000 PREREQUISITE This is Data
I have external-joined the main table so I don't see why it doesn't show up. ...
One of the conditions involving modeofs is an outer join:
... and main.ID = modeOfS.FK_ID(+)
but the other is not:
... and nvl(modeofs.TERM_EFF, 9999) = ( select nvl(max(m2.TERM_EFF), 9999) from modeofs m2 where m2.TERM_EFF <= 2003 and m2.SECTION = modeofs.SECTION and m2.MODE_OF_STUDY = modeofs.MODE_OF_STUDY)
When you use the old notation to join, if no table of x is always marked with a + sign (as in condition 1 above), then all the conditions involving the x table must have a + sign, otherwise the effect will be an inner join. If you find this confusing, you're not alone. It is one of the reasons why I prefer the ANSI join rating:
with ranked_main as ( select main.* , rank () over ( partition by SECTION order by TERM_EFF desc nulls last ) as MAIN_RANK from main where TERM_EFF <= :target_year or TERM_EFF is null ) , ranked_modeofs AS ( SELECT modeofs.* , rank () over ( partition by SECTION , MODE_OF_STUDY order by TERM_EFF desc nulls last ) as MODEOFS_RANK FROM modeofs WHERE TERM_EFF <= :target_year OR TERM_EFF is null ) select master.* , ranked_main.* , ranked_modeOfS.* from master join ranked_main on ranked_main.PROGRAM_CODE = master.PROGRAM_CODE and ranked_main.MAIN_RANK = 1 left outer join ranked_modeOfS on ranked_modeofs.FK_ID = ranked_main.ID and ranked_modeofs.MODEOFS_RANK = 1 ;
-
Replacement of an outer join Null values
Hi all
I am a newbie. Thank you very much for you time. I appreciate your help.
I have a scenario where I have to get all the dates available for a resource. I use the query to do so below.
Select Avail_Date AS MONTH
Id_ressource
OF res_tsk
, (SELECT Rownum - 1 + TRUNC (sysdate) avail_date
OF the double
CONNECT BY ROWNUM < 32
) T2
Where T2. Avail_Date = Trunc ((+) Res_Tsk.Scheduled_Start_Date)
And Resource_Id (+) = 100033868
ORDER BY avail_date
The result of this is:
Month Dates id_ressource
12/03/10 0:00 NULL
04/12/10 0:00 NULL
05/12/10 0:00 NULL
12/06/10 0:00 100033868
As I do an outer join, if the resource is not available on a particular date the id_ressource is coming as NULL because it is not available.
Is it possible to fill this NULL id_ressource with the original id_ressource as the id_ressource is the same for all the result set.
I need the output to be
Month Dates id_ressource
12/03/10 0:00 100033868
04/12/10 0:00 100033868
05/12/10 0:00 100033868
12/06/10 0:00 100033868
Hope I've provided enough information. Once again thanks a lot.Hi, Maddy,
It looks like you want a Partioned Outer Join . This is one of the many things that depends on your version. I could show you a way that works in all versions of Oracle 8.1, but this isn't the best way in more recent versions. Always tell what version of Oracle you are using.
It also helps it that post you a small example of data (CREATE TABLE and INSERT statements) and the outcomes from these data. Simplify as much as possible. For example, instead of covering 32 consecutive days, after a problem involving than, say, 3 days. Just mention that your real problem is 32 days, so people don't post solutions that don't fit well.
Published by: Frank Kulash, December 3, 2010 15:17
728566 wrote:
... by the way, I lost my round today, I used to be pollywog now it's just a number, I wonder why it happened?This happened to me a few weeks before. Update my profile did not help. After about a day, my handle is returned.
It happened again this week. This time, I don't update my profile and my handle is returned about an hour. -
Join inner &; outer join in a query
I have 11 paintings, 10 tables need will always be a match on the id, table 11 may or my not have a football game. I need to print information from the 10 tables with a matching id and the information in the table 11 if a record is found.
Help, please.
There is nothing wrong with having 10 inner joins and 1 outer join.
The syntax might look like this ANSII shaped:
Of
1Table INNER JOIN
2table ON (1Table.key = 2Table.KEY) JOIN IN-HOUSE
3Table ON (1Table.key = 3Table.KEY) JOIN IN-HOUSE
4Table ON (1TAble.key = 4Table.key) JOIN IN-HOUSE
INNER JOIN 5Tableau ON (1Table.key = 5table.key)
6Table ON (1Table.key = 6table.key) JOIN IN-HOUSE
INNER JOIN 7Table ON (1Table.key = 7Table.key)
8Table ON (1Table.key = 8Table.key) JOIN IN-HOUSE
INNER JOIN 9Table ON (1Table.key = 9Table.key)
10Table ON (1Table.key = 10Tablekey) LEFT OUTER JOIN
11Table ON (1Table.key = 11Table.key)
You can use paretheses more group the results if you wish.
When you create a relationship of this process the best resort is to do a table at the same time.
Build the query to return properly the expected effect of the first table. Then add the second and confirm that it is always the desired results. Continue to add the tables one at a time, stable all along the way.
-
Comparing the same outer join column.
Hello
I have the following query.
The problem I have is with the operator1 columns, I've done outer joins on the Users table that contains all users that will be returned in the tables of the peaks and Replens.SELECT Replens.Date1 AS date1, Replens.USER_ID AS Operator1, Picks.USER_ID AS Operator1, Users.Time AS Logged_in_hours, Replens.Quantity AS Pallet_replened, SUM(Replens.Quantity/Users.Time) AS Replen_rate, Picks.Quantity AS Cases_picked, SUM(Picks.Quantity/Users.Time) AS Pick_rate FROM (SELECT libclientreports.getshift(itl.dstamp) Date1, ITL.USER_ID, COUNT(ITL.tag_id) Quantity FROM INVENTORY_TRANSACTION ITL WHERE ITL.code = 'Replenish' AND TO_CHAR(itl.dstamp, 'DD-Mon-YYYY HH24:MI:SS') >= '01-Mar-2010 06:00:00' AND TO_CHAR(itl.dstamp, 'DD-Mon-YYYY HH24:MI:SS') <= '01-Mar-2010 18:00:00' GROUP BY libclientreports.getshift(itl.dstamp), ITL.USER_ID ORDER BY ITL.USER_ID, libclientreports.getshift(itl.dstamp) ) Replens, (SELECT libclientreports.getshift(itl.dstamp) Date1, ITL.USER_ID, SUM(ITL.update_qty) Quantity FROM INVENTORY_TRANSACTION ITL WHERE ITL.to_loc_id = 'CONTAINER' AND TO_CHAR(itl.dstamp, 'DD-Mon-YYYY HH24:MI:SS') >= '01-Mar-2010 06:00:00' AND TO_CHAR(itl.dstamp, 'DD-Mon-YYYY HH24:MI:SS') <= '01-Mar-2010 18:00:00' GROUP BY libclientreports.getshift(itl.dstamp), ITL.USER_ID ORDER BY ITL.USER_ID, libclientreports.getshift(itl.dstamp) ) Picks, (SELECT USER_ID, SUM(LibClientReports.getLoggedInHours (USER_ID, to_date('01-Mar-2010 06:00:00', 'DD-Mon-YYYY HH24:MI:SS'), to_date('01-Mar-2010 18:00:00', 'DD-Mon-YYYY HH24:MI:SS')) )/60 TIME FROM APPLICATION_USER GROUP BY USER_ID ) Users WHERE Users.Time != '0' AND Users.USER_ID = Picks.USER_ID (+) AND Users.USER_ID = Replens.USER_ID (+) GROUP BY Replens.Date1, Replens.USER_ID, Picks.USER_ID, Users.Time, Picks.Quantity, Replens.Quantity ORDER BY Replens.USER_ID, Replens.Date1
However, I want to merge this operator1 into one column. For example, here is the current data, I have for the two columns of the operator 1;
And here is the data I want to see;Operator1 Operator1_1 D9AGY19 D9AGY19 D9BEELB D9BEELB D9FULOPS (null) D9GAWKOWA D9GAWKOWA D9LIDDING D9LIDDING D9NOWAKS D9NOWAKS (null) D9AGY10 (null) D9AGY13 (null) D9AGY15 (null) D9AGY17
Notice the USER_ID to replace the values (null).Operator1 D9AGY19 D9BEELB D9FULOPS D9GAWKOWA D9LIDDING D9NOWAKS D9AGY10 D9AGY13 D9AGY15 D9AGY17
Could someone please explain to me how to make this happen? If you want more information please let me know.
Kind regards
SM.This should do if Op1 and Op1_1 are always the same or one or the other is null. If both are filled and have different values, then it will not work:
nvl(Replens.USER_ID, Picks.User_ID) as AS Operator1
-
I have the following table structure,
_ Table - 1
---------------------------------
ID | Information
---------------------------------
1. abcadskasasa
2. asdasdasdasd
3. saeqdfdvsfcsc
---------------------------------
_ Table - 2
---------------------------------
ID | NEST
---------------------------------
1. 12
1. 13
2. 14
1. 15
1. 16
2. 12
---------------------------------
_ Table - 3
---------------------------------
ID | THIERRY
---------------------------------
1. 12
2. 14
1. 15
---------------------------------
Now, I want to choose for each ID in table 1 and the number of MIP in the table 2-number of THIERRY of table 3.
Desired output:_
---------------------------------------------------------------------------------------------------
ID | COUNT_PID | COUNT_PARID
---------------------------------------------------------------------------------------------------
1. 4. 2
2. 2. 1
3. 0 | 0
---------------------------------------------------------------------------------------------------
Could someone please help me with this. I'm doing using outer joins, but as I work mainly at the edge of the end, not able to reach an appropriate solution to that above.
Thanks in advance,
TejasYou should not outer join... That should do it...
select ID , (select count(PID) from table2 t2 where t2.id = t1.id) , (select count(PARID) from table3 t3 where t3.id = t1.id) from table1
-
SSRS for lack of outer join with the Oracle data source
It seems to be a problem with the Oracle driver used in the Reporting SERVICES query designer.
When you use an Oracle data source, if I create an outer join in the graphic designer, it automatically inserts '{OJ' before the join and '} ' after her. This is an incorrect syntax for Oracle and refuses to start. The curly braces and the JO editable in designer text, but if I go back to the graphic designer and immediately to reintegrate them.
Only, this has started to happen a year or two ago - before that it worked, but with the old (+) syntax.
Can it not be healed? It makes things very difficult.
-Geoff
Hi Geoff,
Thanks for posting in the Microsoft Community.
However, the question you posted would be better suited in the Forums of the Oracle Support; We recommend that you post your query in Oracle Support Forums to get help:
If you have any other questions or you need Windows guru, do not hesitate to post your questions and we will be happy to help you.
-
HELP SQL (auto / full outer join with date corresponding)
I'm having a hard time get this query nailed... hoping someone can help me sorted.
create table tab1 (identification number,
date of eff_date,
Code1 varchar2 (2),
Code2 varchar2 (2)
)
/
insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), 'DAT', 'AS');
insert into tab1 values (2, to_date('2015-03-19','YYYY-MM-DD'), 'DAT', 'AS');
insert into tab1 values (2, to_date('2015-08-28','YYYY-MM-DD'), 'DAT', 'AS');
insert into tab1 values (2, to_date('2015-11-12','YYYY-MM-DD'), 'DAT', 'AS');
insert into tab1 values (2, to_date('2015-01-03','YYYY-MM-DD'), "DAT", "AE");
insert into tab1 values (2, to_date('2015-03-14','YYYY-MM-DD'), "DAT", "AE");
insert into tab1 values (2, to_date('2015-04-18','YYYY-MM-DD'), "DAT", "AE");
insert into tab1 values (2, to_date('2015-09-14','YYYY-MM-DD'), "DAT", "AE");
insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), "DAT", "BS");
insert into tab1 values (2, to_date('2015-02-14','YYYY-MM-DD'), "DAT", "BS");
insert into tab1 values (2, to_date('2015-03-14','YYYY-MM-DD'), "DAT", "BS");
insert into tab1 values (2, to_date('2015-05-14','YYYY-MM-DD'), 'DAT', 'BE');
insert into tab1 values (3, to_date('2015-09-16','YYYY-MM-DD'), 'DAT', 'AS');
insert into tab1 values (3, to_date('2015-04-16','YYYY-MM-DD'), "DAT", "AE");
tab1
ID, date, code 1, code2
2. DID DAT 2015-01-14
2. DID DAT 2015-03-19
2. DID DAT 2015-08-28
2. DID DAT 2015-11-12
2 AE DAT 2015-01-03
2 AE DAT 2015-03-14
2 AE DAT 2015-04-18
2 AE DAT 2015-09-14
2 BS DAT 2015-01-14
2 BS DAT 2015-02-14
2 BS DAT 2015-03-14
BE DAT 2 2015-05-14
3. DID DAT 2015-09-16
3 AE DAT 2015-04-16
What I need to do...
1 auto join to match EI for each partition ID
2. THAT the date must be less than or equal to the date of the AE and when there is more then a line corresponding to this criterion has chosen the date of closest EI of the date of the ACE.
3. it must be a full outer join because I want to show all lines, even if it is not a match. There is a beginning, but not record end end gold but no record of departure
4. If there is an AE line for many AS lines (the SA date is less then equals the date of EI) then join this AE line to all 3 rows of ACE
5. the same rules for BS and BE.
result should look like this.
ID, date, code 1, id_1 code2, date_1, code1_1, code2_1
2 2015-01-14 DAT AS 2 AE DAT 2015-03-14
2 2015-03-19 DAT AS 2 AE DAT 2015-04-18
2 2015-08-28 DAT AS 2 AE DAT 2015-09-14
2 2015-11-12 DAT DID ZERO ZERO ZERO ZERO
NO NO NO NO 2 AE DAT 2015-01-03
2015-01-2 14 DAT BS 2 BE DAT 2015-05-14
2015-02-2 14 DAT BS 2 BE DAT 2015-05-14
2015 03-2 14 DAT BS 2 BE DAT 2015-05-14
3 2015-09-16 DAT DID ZERO ZERO ZERO ZERO
NO NO NO NO 3 AE DAT 2015-04-16
My attempt was somewhat along these lines (dealing only with SA / combos AE) but it does not manage the many scenarios one (req 4).
Select a.*, b.* from
(select row_number () on the rn (partition by a.id order a.eff_date), a.*)
of tab1 where a.code2 = 'AS') a
full outer join
(select row_number () on the rn (b.eff_date order by b.id partition), b.*)
tab1 b where b.code2 = 'Æ') b
on a.id = b.id
and a.rn = b.rn
and a.eff_date < = b.eff_date
Hello
owbdev99 wrote:
I'm having a hard time get this query nailed... hoping someone can help me sorted.
create table tab1 (identification number,
date of eff_date,
Code1 varchar2 (2),
Code2 varchar2 (2)
)
/
insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), 'DAT', 'AS');
...
Thanks for posting the CREATE TABLE and INSERT. I know it can be a lot of trouble. You want to get answers that work, not you? Make sure that the statements you post too much work. Test (and, if necessary, attach) your statements before committing. You said code1 be VARCHAR2, but all the instructions insertion have values of 3 characters for code1.
You are on the right track, with an analytical function, but ROW_NUMBER solves this problem. 1 "THAT line" could correspond to the 1st, 2nd, 3rd or any other line 'AE' and vice versa. Try to use the analytical MIN function instead or ROW_NUMBER, like this:
WITH got_next_e_date AS
(
SELECT id, eff_date, code1, code2
MIN (CASE
WHEN SUBSTR (code2, 2) = 'E '.
THEN eff_date
END
) OVER (PARTITION BY ID.
, SUBSTR (code2, 1, 1)
ORDER BY eff_date DESC
) AS next_e_date
OF tab1
)
s AS
(
SELECT *.
OF got_next_e_date
"WHERE SUBSTR (code2, 2) s ="
)
e
(
SELECT *.
OF got_next_e_date
WHERE SUBSTR (code2, 2) = 'E '.
)
SELECT s.id
s.eff_date
s.code1
s.code2
e.id AS id_1
e.eff_date AS eff_date_1
e.code1 AS code1_1
e.code2 AS code2_1
S
FULL OUTER JOIN e ON s.id = e.id
AND s.next_e_date = e.eff_date
AND SUBSTR (s.code2, 1, 1) = SUBSTR (e.code2, 1, 1)
ORDER OF NVL (s.id, e.id)
, NVL (SUBSTR (s.code2, 1, 1)
, SUBSTR (e.code2, 1, 1)
)
s.eff_date
;
Out (as you asked):
ID EFF_DATE CODE1, CODE2 ID_1 EFF_DATE_1 CODE1_1 CODE2_1
--- ---------- ----- ----- ----- ---------- ------- -------
2 2015-01-14 DAT AS 2 AE DAT 2015-03-14
2 2015-03-19 DAT AS 2 AE DAT 2015-04-18
2 2015-08-28 DAT AS 2 AE DAT 2015-09-14
2. DID DAT 2015-11-12
2 AE DAT 2015-01-03
2015-01-2 14 DAT BS 2 BE DAT 2015-05-14
2015-02-2 14 DAT BS 2 BE DAT 2015-05-14
2015 03-2 14 DAT BS 2 BE DAT 2015-05-14
3. DID DAT 2015-09-16
3 AE DAT 2015-04-16
I guess code2 is always 2 characters, and the 2nd character is always ' or 'E '.
I assume that the combination [id, eff_date, code2] is unique.
If these assumptions are wrong, you need a few minor changes, but nothing big.
-
Outer join does not not as expected left
Hi all
I have it here are three tables with values. Mentioned the under outer join query does not and behave like the inner query.
CREATE TABLE RET_FUND_FEE
(
NPTF VARCHAR2 (8 CHAR),
TPART VARCHAR2 (4 CHAR)
);
CREATE TABLE PART_PTF
(
Mf_Id VARCHAR2 (6 CHAR) NOT NULL,
TPARTS VARCHAR2 (4 CHAR) NOT NULL
);
CREATE TABLE TFC_FUNDS
(
NPTF VARCHAR2 (8 CHAR) NOT NULL,
MULTIFONDS_ID VARCHAR2 (6 CHAR)
);
INSERT INTO RET_FUND_FEE VALUES('111','A');
INSERT INTO RET_FUND_FEE VALUES('111','D');
INSERT INTO RET_FUND_FEE VALUES('111','E');
INSERT INTO PART_PTF VALUES ('MF1', 'A');
INSERT INTO PART_PTF VALUES ('MF1', 'B');
INSERT INTO PART_PTF VALUES('MF1','C');
INSERT INTO TFC_FUNDS VALUES('111','MF1');
INSERT INTO TFC_FUNDS VALUES('111','MF1');
INSERT INTO TFC_FUNDS VALUES('111','MF1');
SELECT A.TPART, B.TPARTS, A.NPTF, B.Mf_Id, C.MULTIFONDS_ID, C.NPTF
OF RET_FUND_FEE A, PART_PTF B, TFC_FUNDS C
WHERE A.NPTF = C.NPTF
AND C.MULTIFONDS_ID = B.Mf_Id
AND A.TPART = B.TPARTS (+)
AND C.MULTIFONDS_ID = 'MF1 '.
AND C.NPTF = '111'
Here, I expect all records in the RET_FUND_FEE table that I am using outer join.
But I'm only corresponding chronogram RET_FUND_FEE, PART_PTF as an inner join. Can you get it someone please let me know what lack us.
Is my version of oracle 11g
SELECT
A.TPART, B.TPARTS, A.NPTF, B.Mf_Id, C.MULTIFONDS_ID, C.NPTF
Of
PART_PTF B
Join
C TFC_FUNDS
on (C.MULTIFONDS_ID = B.Mf_Id
AND C.MULTIFONDS_ID = 'MF1 '.
AND C.NPTF = '111'
)
right outer join
RET_FUND_FEE HAS
on (A.TPART = B.TPARTS
and A.NPTF = C.NPTF) - added as correction
TPART TPARTS NPTF MF_ID MULTIFONDS_ID NPTF A A 111 MF1 MF1 111 A A 111 MF1 MF1 111 A A 111 MF1 MF1 111 E - 111 - - - D - 111 - - - or
SELECT A.TPART, d.TPARTS, A.NPTF, d.Mf_Id, d.MULTIFONDS_ID, d.NPTF
OF RET_FUND_FEE HAS
, (
Select
*
PART_PTF b, TFC_FUNDS C
where B.Mf_Id = C.MULTIFONDS_ID
AND C.MULTIFONDS_ID = 'MF1 '.
AND C.NPTF = '111'
) d
WHERE A.TPART = D.TPARTS (+)
and A.NPTF = D.NPTF (+) - added as a correction
Sorry had to correct the syntax oracle solution.
The first one was bad because it would return also B lines that have no match in C.
Sorry a correction more on these two approaches, missed the second predicate.
-
Oracle: Use LEFT OUTER JOIN, but convert the data to an external list
Hello, all,.
I know it can be done; I just don't remember how I got it done, oh there are so many years.
Assumes that the tables exist for groups and individuals. People can belong to several groups.
SELECT g.groupName, p.lastName || ', ' || p.firstName as fullName FROM groups g LEFT OUTER JOIN groupPersonAssociation gpa ON gpa.groupID = g.groupID LEFT OUTER JOIN person p ON p.personID = gpa.personID ORDER BY g.groupName, fullName
This gives us:
Group One Alpha, Daniel Group One Bravo, Charles Group One Charlie, Chuck Group Two Beta, Alpha Group Two Delta, Bonnie Group Three Echo, Bunny Group Three Golf, Samuel Group Three November, Stan
How word the SQL to get the data as:
Group One Alpha, Daniel | Bravo, Charles | Charlie, Chuck Group Two Beta, Alpha | Delta, Bonnie Group Three Echo, Bunny | Golf, Samuel | November, Stan
V/r,
^_^
I finally thought to it. I was using incorrect keywords on Google.
SELECT g.groupName, LISTAGG(p.lastName || ', ' || p.firstName,' | ') WITHIN GROUP (ORDER BY g.groupName) "fullName" FROM groups g LEFT OUTER JOIN groupPersonAssociation gpa ON ggpa.groupID = g.groupID LEFT OUTER JOIN person p ON p.personID = gpa.personID GROUP BY g.groupName ORDER BY g.groupName, fullName
Just in case someone else is going through this same desire.
HTH,
^_^
Maybe you are looking for
-
Where are the Ports USB 3.0 of my HP Pavilion dv6-6158nr Notebook?
I am unable to find the Ports of USB 3.0 on my HP Pavilion dv6-6158nr laptop. Please tell which side are these ports and how to get the maximum speed out of them?
-
Why I can't see my files on my external hard drive on my Mac?
I got my mac less than a year. I have an external hard drive (external hard drive, Silicon Power A80 - 2 to Armor) and I use it on my MacBook Pro and my PC. Today I just plugged into my mac, and suddenly I saw this error. Should I really reformat bec
-
What could be the problem?
received my phone replaced with motherbaord services center... everything was good, but now when I started to play games, I found something that is annoying My fps decreases while the laptop battery is in charge However When running on battery withou
-
How can I stop the script popping up every second with an error
script appears with an error like (etc) missing. What else can I tell you?
-
Winows XP - cannot install SP1 KB936330 error OX 80070002
When I try to install the above, I get this error message. I have AVG anti - virus free edition installed. Please tell us what to do.