Sub-Query using IN
Hi
I am trying to wite a sub-query that will return the values that exist in the names table and also the address table.
If I knew the values I could write the following: SELECT n.nme_id FROM name n WHERE n.NME_ID IN (1161, 1181);
However, I would like to write it a a sub-query. I have tried the below, but of course it will only put one value (1161) into the IN.
SELECT nme_id
FROM name n
WHERE n.NME_ID IN
(SELECT a.NME_ID
FROM address a);
Could you please tell me how I can provide multiple values sinto the IN statement from a sub-query.
Here is one simulation ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.26
satyaki>
satyaki>
satyaki>select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
9999 SATYAKI SLS 7698 02-NOV-08 55000 3455 10
7777 SOURAV SLS 14-SEP-08 45000 3400 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 4450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 7000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
13 rows selected.
Elapsed: 00:00:01.51
satyaki>
satyaki>select * from t_emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
9999 SATYAKI SLS 7698 02-NOV-08 55100 3455 10
7777 SOURAV SLS 14-SEP-08 45100 3400 10
7521 WARD SALESMAN 7698 22-FEB-81 1350 500 30
7566 JONES MANAGER 7839 02-APR-81 3075 20
9988 KROWN SLS 7698 14-DEC-08 23455 6777 10
Elapsed: 00:00:00.46
satyaki>
satyaki>
satyaki>select empno
2 from emp
3 intersect
4 select empno
5 from t_emp;
EMPNO
7521
7566
7777
9999
Elapsed: 00:00:00.34
satyaki>Regards.
Satyaki De.
Similar Messages
-
Filter query with sub query using Dropdown box
Dear Community,
I have 2 queries
1. Main Query with 2 fields: Project | Project value
2. Sub Query with 2 fields: Project group | Project
Project group can be belonging to number of projects and project can be belong to number of project group (Many to Many).
My customer wants the main query will open without any filtering.
When I choose project group from WAD dropdown box, the main query will filtering all the projects that belong to the project group.
I create WAD; define dropdown box as sub query, and Analysis as main query.
In the dropdown box I choose "data binding" char and create command "set selection state by binding" (project to project) but it doesnu2019t work.
I also try to do this by Replacement Path in the main query, but the variable requires the attribute will be ready for input.
Thanks a lot
YanivI am not sure about your comments on replacement path variable. Without having tried it, here is what I would have attempted:
The main query needs to use a replacement path variable for Project that is replaced by the results of the sub-query. Sub-query would have a regular input variable for project group. (as a quick test, if you had one analysis item for main query with variable input enabled, it should prompt you to enter Project group).
Now the drop-down needs to be associated with a javascript function. The javascript function needs to implement command "Set variable state" for the main query data provider to selected value of the drop-down.
The drop-down should be associated with the sub-query data provider, just used to populate the list of values in drop-down. -
I have a doubt with the use of sub-queries. I am using a query like as below & it is giving me expected result:-
SELECT ISS.item_type_id,count(1) + (select sum(invoiced_qty) from ppbs_invoice_detail where
trunc(created_date) between '01-jul-05' and '04-jul-05' and item_type_id=ISS.item_type_id) qty
FROM ppbs_INV_SIM_SERIAL ISS
WHERE INSTR('ROAAIT',STATUS)>0
AND INSTR('NU0NU1NU2NU3SC0',CITY_CODE) =0
and ISS.item_type_id in ('SM17')
group by ISS.item_type_id --
I will re-write above query & i have been using queries like :-
SELECT ISS.item_type_id,count(1) qty
FROM ppbs_INV_SIM_SERIAL ISS
WHERE INSTR('ROAAIT',STATUS)>0
AND INSTR('NU0NU1NU2NU3SC0',CITY_CODE) =0
and ISS.item_type_id in ('SM17') and item_type_id in
(select item_type_id from ppbs_invoice_detail where
trunc(created_date) between '01-jul-05' and '04-jul-05' and item_type_id=ISS.item_type_id)
group by ISS.item_type_id
my doubt here is that the sub-query in the first query is coming before i use the table 'ppbs_inv_sim_serial ISS' whereas in the second query, the table use 'ppbs_inv_sim_serial ISS' is coming before the sub-query use. I have been using queries where table name is defined before the sub-query.
I hope, my question is clear. Please help in solving the doubt.
Regards.I don't see a problem with the table aliasing that you seem to doubt, but your first query won't run. I boiled the thing down to basics: SQL>create table t1 (one number, val_1 number );
Table created.
SQL>create table t2 (one number, val_2 number );
Table created.
SQL>insert into t1 values (1,1);
1 row created.
SQL>insert into t2 values (1,2);
1 row created.
SQL>select a.one, count(1) + ( select sum(val_2) from t2 where t2.one = a.one) qty
2 from t1 a
3 group by one;
select a.one, count(1) + ( select sum(val_2) from t2 where t2.one = a.one) qty
ERROR at line 1:
ORA-00979: not a GROUP BY expression
SQL>
SQL>select a.one, count(1) qty
2 from t1 a
3 where a.one in ( select one from t2 where one = a.one)
4 group by one;
ONE QTY
1 1It's superfluous to "where a.one in ( select.. where = a.one) but that's your code basically. I would just do "=" -
How to use sub query in CAML in splist
hi,
want to know whether any sub query functionality can be achieved in splist/sp doc lib using CAML designer 2013/ query builder. also inner joins need to be implemented as pe rmy requirement.
if caml designer is not supported, whats the allternative way of doing this?
can LINQ to SP be used? if yes, can anyone pls roivde how to implement the same
help is appreciatedYou can use the let keyword to scope a variable containing the result of your subquery.
However, it depends on the LINQ provider as to whether or not it can understand the command.
For example, you can create the sample like this
var result = (from p in productInQuery
join o in orderInfoQuery on p.refNo equals o.refNo
join t in productOutQuery on p.no equals t.productInNo into productIn
from t in productIn.DefaultIfEmpty()
let dateOut = (from m in orderInfoQuery where m.refNo == t.refNo select m.processData).FirstOrDefault()
orderby o.processDate descending
select new
modelNo = x.modelNo,
qty = p.qty,
dateIn = o.processDate,
dateOut = dateOut
https://www.youtube.com/watch?v=N3K0h6GDwW4
For more info, check this
http://msdn.microsoft.com/en-us/library/ee539975.aspx -
Please suggest a select query / sub query with out using any subprograms or
source table: Three columns ORIGIN, DESTINATION,MILES
Origin Destination Miles
Sydney Melbourne 1000
Perth Adelaide 3000
Canberra Melbounre 700
Melbourne Sydney 1000
Brisbane Sydney 1000
Perth Darwin 4000
Sydney Brisbane 1000
out put :Three columns ORIGIN, DESTINATION,MILES
Duplicate routes are to be ignored so the output is
Origin Destination Miles
Sydney Melbourne 1000
Perth Adelaide 3000
Canberra Melbounre 700
Brisbane Sydney 1000
Perth Darwin 4000
Please suggest a select query / sub query with out using any subprograms or functions/pkgs to get the out put table.Hi,
user9368047 wrote:
... Please suggest a select query / sub query with out using any subprograms or functions/pkgs to get the out put table.Why? If the most efficient way to get the results you want involves using a function, why wouldn't you use it?
Here's one way, without any functions:
SELECT a.*
FROM source_table a
LEFT OUTER JOIN source_table b ON a.origin = b.destination
AND a.destination = b.origin
AND a.miles = b.miles
WHERE b.origin > a.origin -- Not b.origin > b.origin
OR b.origin IS NULL
;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test this.
Edited by: Frank Kulash on Nov 6, 2012 7:39 PM
Corrected WHERE clause after MLVrown (below) -
Use of Sub Query in a filter is throwing error
Hi
I am using a sub query in a filter which throws me the following error in owb 9i.
PLS 00405 : Subquery cannot be used in this context.
But the use of subquery works fine in a joiner operator.
Use of Sub Query in a filter works fine in owb 2i.
Could any one please help me.
Thanks in Advance
Nanda KishoreNanda,
Please wrap the source table in a view containing the subquery and then use the view as a source rather than use the subquery in the filter.
Regards:
Igor -
The issue with using the multiple columns sub-query in WHERE clause
Hi All,
my database version is 10.2.
the problem i am trying to deal with is that when I use multiple column sub-query in the WHERE clause of the SELECT statement, the actual row number returned from the sub-query is different from the whole statement.
And what I found is that, whenever there is NULL in any of those columns returned from the SUB-QUERY, the outer query will just return NULL for that whole row.
Here is an example:
select empno, ename, job, mgr, hiredate, sal, deptno from EMP
intersect
select empno, ename, job, mgr, hiredate, sal, deptno from t;
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7839 KING PRESIDENT NULL 17-NOV-81 5000 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10
select * from EMP where (EMPNO, ENAME, job, MGR, HIREDATE, SAL, DEPTNO) in (
select empno, ename, job, mgr, hiredate, sal, deptno from EMP
intersect
select empno, ename, job, mgr, hiredate, sal, deptno from t);
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10 If I specifically deal with the NULL situations for the columns which might return NULL, I can get the result right.
select * from EMP where (EMPNO, ENAME, job, NVL(MGR,-1), HIREDATE, SAL, DEPTNO) in (
select empno, ename, job, nvl(mgr,-1), hiredate, sal, deptno from EMP
intersect
select empno, ename, job, nvl(mgr,-1), hiredate, sal, deptno from t);
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7839 KING PRESIDENT null 17-NOV-81 5000 10
7934 MILLER CLERK 7782 23-JAN-82 1300 10 the problem is that, I feel this is a very lame way of handling it.
So, I wonder or am asking if there is any better or standard way to do it?
any help would be highly appreciated.
ThanksHi,
As you discovered, INTERSECT treats NULL as a value, but IN does not.
What you did with NVL is one way to handle the situation. If there was a chance that any of the columns could be NULL, then you might prefer something like this:
select *
from EMP
where ( EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
) in (
select EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
from emp
intersect
select EMPNO || '~' ||
ENAME || '~' ||
job || '~' ||
MGR || '~' ||
TO_CHAR (HIREDATE, 'DD-MON-YYYY HH24:MI:SS')
|| '~' ||
SAL || '~' ||
DEPTNO
from t
);This assumes that you can identify some string (I used '~') that never occurs in the strings in these tables.
This is implicitly converting the NUMBERs. That's usually not a good thing to do. but explicitly converting them would make this even more tedious.
You should explicitly convert any DATEs to strings, however. Depending on your default format, and your data, you might get away with implicit conversions even for DATEs, but don't bet on it.
If you had to do this often, you might consider writing a user-defined function:
delimited_string (empno, ename, job, mgr, hiredate, sal, deptno) would return a string like
'7839~KING~PRESIDENT~~17-NOV-1981~5000~10'
This will make the coding easier, but beware: it will make the execution slower. -
Issue with join condition while using in the corelated sub query
Bees,
I am not able to use the below query since i have used a join condition in the corelated sub qery inline view.But i have a requirement like this . Please help me on this
select * from dept d
where exists (select 1 from (
select deptno
from emp where deptno= d.deptno)
Thank you
BooooHi,
I've never seen a general solution for how to reference columns from main query a from sub-query c, where c is is sub-query of b, which is a sub-query of a.
Whenever I've wanted to, I've been able to get the desired results with a different approach.
In this case, you seem to want
SELECT *
FROM dept d
WHERE EXISTS (
SELECT 1
FROM emp
WHERE deptno = d.deptno
);I'm guessing at your data and desired output. -
Can i use Sub Query Factoring Here ?
Hi;
SQL>SELECT * FROM V$VERSION;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for Linux: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - ProductionSQL
select /*+ PARALLEL(det, 4) */ '12062' snapshot_id,det.journal_entry_line_id, det.accounting_date,det.company_code,det.account_number,
det.transaction_id, det.transaction_id_type, det.amount,det.currency_code,det.debit_or_credit,det.category,det.subcategory,det.reference1,det.reference1_type,
det.reference2,det.reference2_type,det.gl_batch_id,det.marketplace_id,det.cost_center,det.gl_product_line,det.location,det.project,det.sales_channel,
det.created_by,det.creation_date,det.last_updated_by,det.last_updated_date,agg.age,last_day(to_date('04/21/2010','MM/DD/YYYY')) snapshot_day
from
select company_code, account_number, transaction_id,
decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,
(last_day(to_date('04/21/2010','MM/DD/YYYY')) - min(z.accounting_date) ) age,sum(z.amount)
from
select /*+ PARALLEL(use, 2) */ company_code,substr(account_number, 1, 5) account_number,transaction_id,
decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,use.amount,use.accounting_date
from financials.unbalanced_subledger_entries use
where use.accounting_date >= to_date('04/21/2010','MM/DD/YYYY')
and use.accounting_date < to_date('04/21/2010','MM/DD/YYYY') + 1
UNION ALL
select /*+ PARALLEL(se, 2) */ company_code, substr(se.account_number, 1, 5) account_number,transaction_id,
decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,se.amount,se.accounting_date
from financials.temp2_sl_snapshot_entries se,financials.account_numbers an
where se.account_number = an.account_number
and an.subledger_type in ('C', 'AC')
) z
group by company_code,account_number,transaction_id,decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type)
having abs(sum(z.amount)) >= 0.01
) agg,
select /*+ PARALLEL(det, 2) */ det.journal_entry_line_id, det.accounting_date, det.company_code, det.account_number, det.transaction_id, decode(det.transaction_id_type, 'CollectionID', 'SettlementGroupID', det.transaction_id_type) transaction_id_type,
det.amount, det.currency_code, det.debit_or_credit, det.category, det.subcategory, det.reference1, det.reference1_type, det.reference2, det.reference2_type,
det.gl_batch_id, det.marketplace_id, det.cost_center, det.gl_product_line, det.location, det.project, det.sales_channel, det.created_by, det.creation_date,
det.last_updated_by, det.last_updated_date
from financials.unbalanced_subledger_entries det
where accounting_date >= to_date('04/21/2010','MM/DD/YYYY')
and accounting_date < to_date('04/21/2010','MM/DD/YYYY') + 1
UNION ALL
select /*+ PARALLEL(det, 2) */ det.journal_entry_line_id, det.accounting_date, det.company_code, det.account_number, det.transaction_id,
decode(det.transaction_id_type, 'CollectionID', 'SettlementGroupID', det.transaction_id_type) transaction_id_type, det.amount, det.currency_code,
det.debit_or_credit, det.category, det.subcategory, det.reference1, det.reference1_type, det.reference2, det.reference2_type, det.gl_batch_id, det.marketplace_id,
det.cost_center, det.gl_product_line, det.location, det.project, det.sales_channel, det.created_by, det.creation_date, det.last_updated_by, det.last_updated_date
from financials.temp2_sl_snapshot_entries det,financials.account_numbers an
where det.account_number = an.account_number
and an.subledger_type in ('C', 'AC')
) det
where agg.company_code = det.company_code
and agg.account_number = substr(det.account_number, 1, 5)
and agg.transaction_id = det.transaction_id
and agg.transaction_id_type = det.transaction_id_type
/Execution Plan
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
| 0 | SELECT STATEMENT | | 12M| 8012M| | 541K (1)| 01:48:21 | | | |
| 1 | PX COORDINATOR | | | | | | | | | |
| 2 | PX SEND QC (RANDOM) | :TQ10005 | 12M| 8012M| | 541K (1)| 01:48:21 | Q1,05 | P->S | QC (RAND) |
|* 3 | HASH JOIN BUFFERED | | 12M| 8012M| 1098M| 541K (1)| 01:48:21 | Q1,05 | PCWP | |
| 4 | PX RECEIVE | | 35M| 3992M| | 166K (2)| 00:33:16 | Q1,05 | PCWP | |
| 5 | PX SEND HASH | :TQ10003 | 35M| 3992M| | 166K (2)| 00:33:16 | Q1,03 | P->P | HASH |
| 6 | VIEW | | 35M| 3992M| | 166K (2)| 00:33:16 | Q1,03 | PCWP | |
|* 7 | FILTER | | | | | | | Q1,03 | PCWC | |
| 8 | HASH GROUP BY | | 35M| 4528M| | 166K (2)| 00:33:16 | Q1,03 | PCWP | |
| 9 | PX RECEIVE | | 35M| 4528M| | 166K (2)| 00:33:16 | Q1,03 | PCWP | |
| 10 | PX SEND HASH | :TQ10001 | 35M| 4528M| | 166K (2)| 00:33:16 | Q1,01 | P->P | HASH |
| 11 | HASH GROUP BY | | 35M| 4528M| | 166K (2)| 00:33:16 | Q1,01 | PCWP | |
| 12 | VIEW | | 35M| 4528M| | 164K (1)| 00:33:00 | Q1,01 | PCWP | |
| 13 | UNION-ALL | | | | | | | Q1,01 | PCWP | |
| 14 | PX BLOCK ITERATOR | | 11 | 539 | | 1845 (1)| 00:00:23 | Q1,01 | PCWC | |
|* 15 | TABLE ACCESS FULL | UNBALANCED_SUBLEDGER_ENTRIES | 11 | 539 | | 1845 (1)| 00:00:23 | Q1,01 | PCWP | |
|* 16 | HASH JOIN | | 35M| 2012M| | 163K (1)| 00:32:37 | Q1,01 | PCWP | |
| 17 | BUFFER SORT | | | | | | | Q1,01 | PCWC | |
| 18 | PX RECEIVE | | 21 | 210 | | 2 (0)| 00:00:01 | Q1,01 | PCWP | |
| 19 | PX SEND BROADCAST | :TQ10000 | 21 | 210 | | 2 (0)| 00:00:01 | | S->P | BROADCAST |
|* 20 | TABLE ACCESS FULL| ACCOUNT_NUMBERS | 21 | 210 | | 2 (0)| 00:00:01 | | | |
| 21 | PX BLOCK ITERATOR | | 56M| 2701M| | 162K (1)| 00:32:35 | Q1,01 | PCWC | |
| 22 | TABLE ACCESS FULL | TEMP2_SL_SNAPSHOT_ENTRIES | 56M| 2701M| | 162K (1)| 00:32:35 | Q1,01 | PCWP | |
| 23 | PX RECEIVE | | 35M| 18G| | 82859 (1)| 00:16:35 | Q1,05 | PCWP | |
| 24 | PX SEND HASH | :TQ10004 | 35M| 18G| | 82859 (1)| 00:16:35 | Q1,04 | P->P | HASH |
| 25 | BUFFER SORT | | 12M| 8012M| | | | Q1,04 | PCWP | |
| 26 | VIEW | | 35M| 18G| | 82859 (1)| 00:16:35 | Q1,04 | PCWP | |
| 27 | UNION-ALL | | | | | | | Q1,04 | PCWP | |
| 28 | PX BLOCK ITERATOR | | 11 | 2255 | | 923 (1)| 00:00:12 | Q1,04 | PCWC | |
|* 29 | TABLE ACCESS FULL | UNBALANCED_SUBLEDGER_ENTRIES | 11 | 2255 | | 923 (1)| 00:00:12 | Q1,04 | PCWP | |
|* 30 | HASH JOIN | | 35M| 7514M| | 81936 (1)| 00:16:24 | Q1,04 | PCWP | |
| 31 | PX RECEIVE | | 21 | 210 | | 2 (0)| 00:00:01 | Q1,04 | PCWP | |
| 32 | PX SEND BROADCAST | :TQ10002 | 21 | 210 | | 2 (0)| 00:00:01 | Q1,02 | P->P | BROADCAST |
| 33 | PX BLOCK ITERATOR | | 21 | 210 | | 2 (0)| 00:00:01 | Q1,02 | PCWC | |
|* 34 | TABLE ACCESS FULL | ACCOUNT_NUMBERS | 21 | 210 | | 2 (0)| 00:00:01 | Q1,02 | PCWP | |
| 35 | PX BLOCK ITERATOR | | 56M| 11G| | 81840 (1)| 00:16:23 | Q1,04 | PCWC | |
| 36 | TABLE ACCESS FULL | TEMP2_SL_SNAPSHOT_ENTRIES | 56M| 11G| | 81840 (1)| 00:16:23 | Q1,04 | PCWP | |
Predicate Information (identified by operation id):
3 - access("AGG"."COMPANY_CODE"="DET"."COMPANY_CODE" AND "AGG"."ACCOUNT_NUMBER"=SUBSTR("DET"."ACCOUNT_NUMBER",1,5) AND
"AGG"."TRANSACTION_ID"="DET"."TRANSACTION_ID" AND "AGG"."TRANSACTION_ID_TYPE"="DET"."TRANSACTION_ID_TYPE")
7 - filter(ABS(SUM(SYS_OP_CSR(SYS_OP_MSR(SUM("Z"."AMOUNT"),MIN("Z"."ACCOUNTING_DATE")),0)))>=0.01)
15 - filter("USE"."ACCOUNTING_DATE"<TO_DATE(' 2010-04-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "USE"."ACCOUNTING_DATE">=TO_DATE('
2010-04-21 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
16 - access("SE"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
20 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
29 - filter("ACCOUNTING_DATE"<TO_DATE(' 2010-04-22 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ACCOUNTING_DATE">=TO_DATE(' 2010-04-21
00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
30 - access("DET"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
34 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
This query is failing due to TEMP issue (TEMP SPACE out of space)
My TEMP tablespace is 70GB and no one is using TEMP space while this query is in execution.
PGA=16 GB.
What i can see from execution plan is : Two large resultsets AGG (13Million) and DET (135 Million) is being joined HASH JOIN BUFFERED. Which is getting spilled to TEMP space causing TEMP outage.
Is there any way, i can re-write this query (probably using SUB QUERY FACTORING...WITH CLAUSE) so that reduce two times access to TEMP2_SL_SNAPSHOT_ENTRIES table. TEMP2_SL_SNAPSHOT_ENTRIES is 12 GB non partition table and i cannot use any other filter to restrict rows from this table.Adding more information here :
Inner sub query (Which forms DET-bottom)
select /*+ PARALLEL(det, 2) */ det.journal_entry_line_id, det.accounting_date, det.company_code, det.account_number, det.transaction_id,
decode(det.transaction_id_type, 'CollectionID', 'SettlementGroupID', det.transaction_id_type) transaction_id_type, det.amount, det.currency_code,
det.debit_or_credit, det.category, det.subcategory, det.reference1, det.reference1_type, det.reference2, det.reference2_type, det.gl_batch_id, det.marketplace_id,
det.cost_center, det.gl_product_line, det.location, det.project, det.sales_channel, det.created_by, det.creation_date, det.last_updated_by, det.last_updated_date
from financials.temp2_sl_snapshot_entries det,financials.account_numbers an
where det.account_number = an.account_number
and an.subledger_type in ('C', 'AC');
Plan hash value: 976020246
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
| 0 | SELECT STATEMENT | | 35M| 7514M| 163K (1)| 00:32:47 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM) | :TQ10001 | 35M| 7514M| 163K (1)| 00:32:47 | Q1,01 | P->S | QC (RAND) |
|* 3 | HASH JOIN | | 35M| 7514M| 163K (1)| 00:32:47 | Q1,01 | PCWP | |
| 4 | BUFFER SORT | | | | | | Q1,01 | PCWC | |
| 5 | PX RECEIVE | | 21 | 210 | 2 (0)| 00:00:01 | Q1,01 | PCWP | |
| 6 | PX SEND BROADCAST | :TQ10000 | 21 | 210 | 2 (0)| 00:00:01 | | S->P | BROADCAST |
|* 7 | TABLE ACCESS FULL| ACCOUNT_NUMBERS | 21 | 210 | 2 (0)| 00:00:01 | | | |
| 8 | PX BLOCK ITERATOR | | 56M| 11G| 163K (1)| 00:32:45 | Q1,01 | PCWC | |
| 9 | TABLE ACCESS FULL | TEMP2_SL_SNAPSHOT_ENTRIES | 56M| 11G| 163K (1)| 00:32:45 | Q1,01 | PCWP | |
Predicate Information (identified by operation id):
3 - access("DET"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
7 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
Statistics
31 recursive calls
3 db block gets
1634444 consistent gets
1625596 physical reads
636 redo size
1803659818 bytes sent via SQL*Net to client
125054 bytes received via SQL*Net from client
11331 SQL*Net roundtrips to/from client
3 sorts (memory)
0 sorts (disk)
56645822 rows processedOther sub query (that forms AGG)
select /*+ PARALLEL(se, 2) */ company_code, substr(se.account_number, 1, 5) account_number,transaction_id,
decode(transaction_id_type, 'CollectionID', 'SettlementGroupID', transaction_id_type) transaction_id_type,se.amount,se.accounting_date
from financials.temp2_sl_snapshot_entries se,financials.account_numbers an
where se.account_number = an.account_number
and an.subledger_type in ('C', 'AC');
Plan hash value: 976020246
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
| 0 | SELECT STATEMENT | | 35M| 2012M| 163K (1)| 00:32:37 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM) | :TQ10001 | 35M| 2012M| 163K (1)| 00:32:37 | Q1,01 | P->S | QC (RAND) |
|* 3 | HASH JOIN | | 35M| 2012M| 163K (1)| 00:32:37 | Q1,01 | PCWP | |
| 4 | BUFFER SORT | | | | | | Q1,01 | PCWC | |
| 5 | PX RECEIVE | | 21 | 210 | 2 (0)| 00:00:01 | Q1,01 | PCWP | |
| 6 | PX SEND BROADCAST | :TQ10000 | 21 | 210 | 2 (0)| 00:00:01 | | S->P | BROADCAST |
|* 7 | TABLE ACCESS FULL| ACCOUNT_NUMBERS | 21 | 210 | 2 (0)| 00:00:01 | | | |
| 8 | PX BLOCK ITERATOR | | 56M| 2701M| 162K (1)| 00:32:35 | Q1,01 | PCWC | |
| 9 | TABLE ACCESS FULL | TEMP2_SL_SNAPSHOT_ENTRIES | 56M| 2701M| 162K (1)| 00:32:35 | Q1,01 | PCWP | |
Predicate Information (identified by operation id):
3 - access("SE"."ACCOUNT_NUMBER"="AN"."ACCOUNT_NUMBER")
7 - filter("AN"."SUBLEDGER_TYPE"='AC' OR "AN"."SUBLEDGER_TYPE"='C')
Statistics
31 recursive calls
3 db block gets
1634444 consistent gets
1625596 physical reads
592 redo size
1803659818 bytes sent via SQL*Net to client
125054 bytes received via SQL*Net from client
11331 SQL*Net roundtrips to/from client
3 sorts (memory)
0 sorts (disk)
56645822 rows processed -
Sub Query or Use Result of Query on OLAP BW Universe ?
Dear All,
Could you use in Webi report :
1 ) Sub Query ? I activate the option with Designer but button is still in grey...
2 ) Result of query on filter panel ? The button is still in grey
Regards
CédricHi ,
I do it before my initial post... without success.
I already use Sub Query in relational database, but with OLAP BW universe, I can't use actually...
I am searching info, solution,...
Thanks
Cédric -
Can i join a list in sub-site using Join query?
Hi all,
I'm newbie and i have tried to join a list in parent site with a list in sub-site using Join query but i always get the error. How can i do this action? Thanks!You could try using SPSiteDataQuery or a DataTable.
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery%28v=office.14%29.aspx
http://sharepoint.stackexchange.com/questions/75713/is-it-possible-to-populate-result-by-joining-two-lists-throughout-the-site-colle
--Cheers -
How to get all rows that are returned in inner sub query of select statemen
If a sub query in select statement returns more than one row than how to get all those returned rows in the final
output of the query .It will be all right if all column's value repeat and that multiple output of inner query comes
in another column .
How to get that ?As Frank said, you likely want a join, and likely an outer join to replicate the select in the projection. Something like:
SELECT id,stat, section, USER_ID concerned_person
FROM table_all,
left join table2
on room_id = sectoion and
sur_role = 'r001'
WHERE section IN (SELECT code
FROM t_area
WHERE dept= 'p002')An alternative, depending on where and how you are using the statement would be something like:
SQL> WITH t AS (
2 select 1 id from dual union all
3 select 2 id from dual),
4 t1 as (
5 select 1 id, 'One' descr from dual union all
6 select 1, 'Un' from dual union all
7 select 1, 'Une' from dual)
8 SELECT t.id, CURSOR(SELECT t1.id, t1.descr from t1
9 WHERE t1.id = t.id)
10 FROM t;
ID CURSOR(SELECTT1.ID,T
1 CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
ID DESCR
1 One
1 Un
1 Une
2 CURSOR STATEMENT : 2
CURSOR STATEMENT : 2
no rows selectedJohn -
How to find out which sub query returns more than one row
Hi all,
Can any one give me clue ,how to find out which sub query returns more than one row in the following query .
/* Formatted on 2011/05/17 19:22 (Formatter Plus v4.8.8) */
SELECT a.*, ROWNUM AS rnm
FROM (SELECT DISTINCT '1' AS "Page View", ou.org_unit_name AS "Org",
prxm.mbr_idntfr AS "Beneficiary ID",
md.last_name
|| ', '
|| md.first_name AS "Beneficiary Name",
pci.idntfr AS "Tracking No.",
TO_CHAR (TRUNC (req.pa_rqst_date),
'MM/dd/yyyy'
) AS "Request Date",
sts.status_name AS "Status",
req.pa_rqst_sid AS "Request #",
prxm.mbr_sid AS "Mbr_sid",
TO_CHAR
(TRUNC (req.pa_revision_date),
'MM/dd/yyyy'
) AS "Last Updated",
TO_CHAR (psd.TO_DATE, 'MM/dd/yyyy') AS "TO_DATE",
prxpl.prvdr_lctn_iid AS "PRVDR_LCTN_IID",
pd.prvdr_sid AS "PRVDR_SID", 'Y' AS "State View",
DECODE
((SELECT DISTINCT pd.national_prvdr_idntfr
FROM pa_request_x_provider_location prxplo
WHERE prxplo.pa_rqst_sid =
req.pa_rqst_sid
AND prxplo.oprtnl_flag = 'A'
AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
0, (SELECT prxplo.prvdr_lctn_idntfr
FROM pa_request_x_provider_location prxplo
WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
AND prxplo.oprtnl_flag = 'A'
AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
NULL, (SELECT prxplo.prvdr_lctn_idntfr
FROM pa_request_x_provider_location prxplo
WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
AND prxplo.oprtnl_flag = 'A'
AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
(SELECT DISTINCT pd.national_prvdr_idntfr
FROM pa_request_x_provider_location prxplo
WHERE prxplo.pa_rqst_sid =
req.pa_rqst_sid
AND prxplo.oprtnl_flag = 'A'
AND prxplo.pa_prvdr_type_lkpcd = 'RR')
) AS "NPI/ID",
DECODE
((SELECT pd.org_bsns_name
FROM pa_request_x_provider_location prxplo
WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
AND prxplo.oprtnl_flag = 'A'
AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
NULL, (SELECT pd.last_name
|| ', '
|| pd.first_name
|| ' '
|| pd.middle_name
FROM pa_request_x_provider_location prxplo
WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
AND prxplo.oprtnl_flag = 'A'
AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
(SELECT pd.org_bsns_name
FROM pa_request_x_provider_location prxplo
WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
AND prxplo.oprtnl_flag = 'A'
AND prxplo.pa_prvdr_type_lkpcd = 'RR')
) AS "Prvdr Name",
TO_CHAR (psd.from_date,
'MM/dd/yyyy'
) AS "Srvc From Date",
TO_CHAR (req.validity_start_date,
'MM/DD/YYYY'
) AS "Due Date",
(fn_get_busniess_days (TRUNC (req.validity_start_date))
) AS "Days<br>Left",
req.pa_mode_type_lkpcd AS "Source",
TO_CHAR (TRUNC (wmdtl.rtng_date),
'MM/dd/yyyy'
) AS "Assigned On",
NVL (wmdtl.assigned_to_user_name,
'Not Assigned'
) AS "Assigned To",
req.org_unit_sid AS "OrgUnitSid",
TO_CHAR
(wmdtl.modified_date,
'MM/dd/yyyy hh24:mi:ss'
) AS "WTRD_MODIFIED_DATE",
TO_CHAR (wmdtl.rtng_date,
'MM/dd/yyyy'
) AS "WTRD_RTNG_DATE",
req.status_cid AS "PA_STATUS_CID",
TO_CHAR (req.modified_date,
'MM/dd/yyyy'
) AS "PA_REQ_MODIFIED_DATE",
prs.state_pa_srvc_type_code
AS "STATE_PA_SRVC_TYPE_CODE",
wmdtl.wm_pa_task_rtng_dtl_sid
AS "WM_TASK_RTNG_DTL_SID",
wmdtl.assigned_to_user_acct_sid
AS "WTRD_Assigned_to_user_acct_sid",
(fn_get_busniess_days (TRUNC (req.validity_start_date))
) AS "Days<br>LeftSort",
wmdtl.assigned_to_org_unit_sid
AS "WTRD_Assigned_to_OrgUntSid",
DECODE
((SELECT COUNT (*)
FROM pa_request_status prs
WHERE prs.pa_rqst_sid = req.pa_rqst_sid
AND prs.status_cid = 5
AND prs.oprtnl_flag = 'I'),
0, 'N',
'Y'
) AS "SHOW_UTILIZATION"
FROM pa_request req,
pa_certification_identifier pci,
status sts,
pa_request_x_member prxm,
wm_pa_task_routing_detail wmdtl,
pa_service_date psd,
org_unit ou,
pa_request_service prs,
pa_request_x_provider_location prxpl,
provider_location pl,
provider_detail pd,
provider p,
mbr_dmgrphc md
WHERE req.oprtnl_flag = 'A'
AND req.status_cid NOT IN
(20, 30, 70, 25, 80, 96, 85, 5, 97, 98, 101)
AND req.org_unit_sid IN
(3057, 3142, 3058, 3143, 3059, 3144, 3060, 3145,
3061, 3146, 3062, 3147, 3063, 3148, 3064, 3149,
3065, 3150, 3066, 3151, 3067, 3152, 3068, 3153,
3069, 3154, 3070, 3155, 3071, 3156, 3072, 3157,
3073, 3158, 3074, 3159, 3075, 3160, 3076, 3161,
3077, 3162, 3078, 3163, 3079, 3164, 3080, 3165,
3081, 3166, 3082, 3167, 3083, 3168, 3084, 3169,
3085, 3170, 3086, 3171, 3087, 3172, 3088, 3173,
3089, 3174, 3090, 3175, 3091, 3176, 3092, 3177,
3093, 3178, 3094, 3179, 3095, 3180, 3096, 3181,
3097, 3182, 3098, 3183, 3099, 3184, 3100, 3185,
3101, 3186, 3102, 3187, 3103, 3003, 75000104,
75000108, 2006, 75000103, 75000102, 75000113,
75000111, 75000109, 2001, 2009, 75000105,
75000107, 2004, 2010, 2013, 2014, 2005, 2011,
75000112, 2002, 1001, 2012, 75000106, 2007,
75000101, 2003, 75000110, 2008, 3001, 3002, 3019,
3104, 3020, 3105, 3021, 3106, 3022, 3107, 3023,
3108, 3024, 3109, 3025, 3110, 3026, 3111, 3027,
3112, 3028, 3113, 3029, 3114, 3030, 3115, 3031,
3116, 3032, 3117, 3033, 3118, 3034, 3119, 3035,
3120, 3036, 3121, 3037, 3122, 3038, 3123, 3039,
3124, 3040, 3125, 3041, 3126, 3042, 3127, 3043,
3128, 3044, 3129, 3045, 3130, 3046, 3131, 3047,
3132, 3048, 3133, 3049, 3134, 3050, 3135, 3051,
3136, 3052, 3137, 3053, 3138, 3054, 3139, 3055,
3140, 3056, 3141)
AND req.pa_rqst_sid = prs.pa_rqst_sid
AND prs.oprtnl_flag = 'A'
AND prs.pa_rqst_srvc_sid = psd.pa_rqst_srvc_sid
AND psd.oprtnl_flag = 'A'
AND req.pa_rqst_sid = pci.pa_rqst_sid
AND pci.oprtnl_flag = 'A'
AND req.pa_rqst_sid = prxm.pa_rqst_sid
AND prxm.oprtnl_flag = 'A'
AND md.oprtnl_flag = 'A'
AND md.status_cid = 2
AND TRUNC (SYSDATE) BETWEEN md.from_date AND md.TO_DATE
AND prxm.mbr_sid = md.mbr_sid
AND ou.org_unit_sid = req.org_unit_sid
AND ou.oprtnl_flag = 'A'
AND req.pa_rqst_sid = prxpl.pa_rqst_sid
AND prxm.pa_rqst_sid = prxpl.pa_rqst_sid
AND pci.pa_rqst_sid = prxm.pa_rqst_sid
AND pci.pa_rqst_sid = wmdtl.subsystem_task_sid
AND pci.pa_rqst_sid = prxpl.pa_rqst_sid
AND prxpl.pa_prvdr_type_lkpcd = 'RR'
AND prxpl.oprtnl_flag = 'A'
AND req.status_cid = sts.status_cid
AND sts.status_type_cid = 3
AND sts.oprtnl_flag = 'A'
AND prxpl.prvdr_lctn_iid = pl.prvdr_lctn_iid
AND p.prvdr_sid = pd.prvdr_sid
AND p.prvdr_sid = pl.prvdr_sid
AND pd.oprtnl_flag = 'A'
AND pd.status_cid = 2
AND TRUNC (SYSDATE) BETWEEN pd.from_date AND pd.TO_DATE
AND wmdtl.subsystem_task_sid = req.pa_rqst_sid
AND wmdtl.subsystem_lkpcd = 'PA'
AND wmdtl.oprtnl_flag = 'A'
AND req.pa_rqst_date > (SYSDATE - 365)
ORDER BY TO_DATE ("Request Date", 'MM/dd/yyyy hh24:mi:ss') DESC,
"Beneficiary Name" ASC) a
WHERE ROWNUM < 102;regards,
P Prakash
Edited by: BluShadow on 17-May-2011 15:01
added {noformat}{noformat} tags around the code833560 wrote:
Can any one give me clue ,how to find out which sub query returns more than one row in the following query .This is why smaller, simpler queries are easier to work with than huge ones - when something like this goes wrong smaller queries are much eaiser to debug. Unfortunately using smaller, easier-to-work with queries is not always an option
Ganesh is right - you will have to dissect the big query bit by bit until you find the offending subquery. If there is another way I would like to find out about it too.
The easiest way to do this is probably to use block comments to isolate parts of the query bit by bit until you find the offending part. If you carefully examine the subqueries you might be able to figure out which one is returning multiple rows without commenting everything
Good luck! -
Hi, I have two issues, here is my initial code:
select
cc.name_id_no
,cc.discover_date
,cc.cla_case_no
,max(rl.year_of_incident)Non_Loss_Past_5
,rl.timestamp
from cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc(cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc(cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
--and (trunc(cc.discover_date) <> (rl.year_of_incident))
group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
Now a cla_case_no can map to several year_of_incident. I only want the cla_case_no that maps to the max year_of_incident ie There should only be a single cla_case_no corresponding to the max year_of_incident.
To get around this I did the following which is not very efficient and I'm hoping it can be improved:
select distinct z.cla_case_no from (
select
cc.name_id_no
,cc.discover_date
,cc.cla_case_no
,max(rl.year_of_incident)Non_MW_Loss_Past_5
,rl.timestamp
from cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc(cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc(cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
--and (trunc(cc.discover_date) <> (rl.year_of_incident))
group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
) z
Now comes the second issue: The above is actually a subquery that will link to a bigger table via cla_case_no ccx
SELECT
ie ,(select distinct z.cla_case_no from (
select cc.name_id_no, cc.discover_date ,cc.cla_case_no, max(rl.year_of_incident)Non_MW_Loss_Past_5, rl.timestamp
from cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc(cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc(cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
--and (trunc(cc.discover_date) <> (rl.year_of_incident))
group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
) z
where z.cla_case_no = ccx.cla_case_no
) Non_MW_Loss_Past_5
FROM etc
Now only certain cc.cla_case_no from the subquery will corresp to the ccx_cla_case_no from the main table and the other entries will be null.
What I require is that if the subquery returns a result that IS NOT NULL to return 'Y' ELSE 'N' instead of the varies cla_case_no's and (null) entries in the Non_MW_Loss_Past_5 column
Thanks!!!
Banner:
Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
"CORE 11.2.0.2.0 Production"
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - ProductionHi,
It looks like you have another copy of this question:
Case Statement and sub query
That's probably not your fault, but you should mark the other copy as "Answered" right away, and then you'll only have to look for replies in one place.
885178 wrote:
... Now a cla_case_no can map to several year_of_incident. I only want the cla_case_no that maps to the max year_of_incident ie There should only be a single cla_case_no corresponding to the max year_of_incident.If you know there will only be one, then you can use LAST, and you don't need GrOUP BY
To get around this I did the following which is not very efficient and I'm hoping it can be improved:
select distinct z.cla_case_no from (
select
cc.name_id_no
,cc.discover_date
,cc.cla_case_no
,max(rl.year_of_incident)Non_MW_Loss_Past_5
,rl.timestamp
from cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc(cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc(cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
--and (trunc(cc.discover_date) <> (rl.year_of_incident))
group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
) zHere's one way:
SELECT MIN (cla_case_no) KEEP (DENSE_RANK LAST ORDER BY r1.year_of_incident)
AS latest_cla_case_no
FROM cla_case cc
, rbn_loss rl
WHERE cc.name_id_no = rl.customer_no
AND rl.year_of_incident > TRUNC (cc.discover_date) - 1095
AND rl.year_of_incident < TRUNC (cc.discover_date)
AND rl.type_of_loss < 1000
AND rl.timestamp < TRUNC (cc.discover_date)
AND cc.question_class IN (20, 25)
;If you'd post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data, then I could test this.
Now comes the second issue: The above is actually a subquery that will link to a bigger table via cla_case_no ccx
SELECT
ie ,(select distinct z.cla_case_no from (
select cc.name_id_no, cc.discover_date ,cc.cla_case_no, max(rl.year_of_incident)Non_MW_Loss_Past_5, rl.timestamp
from cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc(cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc(cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
--and (trunc(cc.discover_date) <> (rl.year_of_incident))
group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
) z
where z.cla_case_no = ccx.cla_case_no
) Non_MW_Loss_Past_5
FROM etc
Now only certain cc.cla_case_no from the subquery will corresp to the ccx_cla_case_no from the main table and the other entries will be null.
What I require is that if the subquery returns a result that IS NOT NULL to return 'Y' ELSE 'N' instead of the varies cla_case_no's and (null) entries in the Non_MW_Loss_Past_5 column
NVL2 (x, 'Y', 'N')returns 'Y' if x is NULL, and it returns 'N' if x is not NULL. X can be a scalar sub-query:
NVL2 ((SELECT ...), 'Y', 'N')You could also use an EXISTS sub-query:
CASE
WHEN EXISTS (SELECT ...)
THEN 'Y'
ELSE 'N'
END -
Hi,
Can we use order by clause in Sub query?
While using the order by clause, I am getting the "missing expression error" . If I remove order by clause query executing fine.
Here is my query:
select *
from emp_mstr
where emp_no in(select
emp_no
from emp_mstr
order by branch_no);
Thanks & Regards,
MahiMay be you miss some required spaces also, other than wrong use of ORDER BY
select *
from emp_mstr
where emp_no in
( select e2.emp_no
from emp_mstr e2
-- order by e2.branch_no
);Why do you want to ORDER BY in the subquery, which you use with IN clause? That will not make any difference in the result..Means the result you get with ORDER BY will be same as without that.. And in this case, ORDER by is a unncessary overhead.. And Ordering is very costly..
And why do you want to have the IN clause at all in your query? You are referring the same tables in the main query and sub query..
The below will give the same result
select *
from emp_mstr
where emp_no is not nullIf you want to use another table in the subquery, always use aliasess...
select *
from emp_mstr
where emp_no in
( select e2.emp_no
from emp_mstr2 e2
-- order by e2.branch_no
);
Maybe you are looking for
-
How can I use interpolators in this problem
Hi All, I have solid sphere and I want draw motion appear on the surface of the sphere between any 2 points on sphere surface. please help me, I need it urgently Regards, Walaa
-
I am new to jdeveloper/bpel (v. 10.1.3.4) and am trying to import a schema from *[http://www.openapplications.org/oagis/9]*. The entire oagis schema (about 1GB) has been downloaded to my hard drive (is this necessary or can a url be used). I create a
-
MIT Kerberos integration via Oracle ASO for Instant Client
Is Oracle planning on adding support for the Oracle ASO module (specifically for the use of MIT Kerberos authentication) to the Oracle Instant Client? Last time I checked (about 2 years ago) they had not, but I'm hoping they are working on it. Update
-
Hi I need to do a Trigger with temporal tables, I did in SQL Server but now I dont't know if can do this code with Oracle. I'll be glad if you send me a example with temporal tables. ALGORITMO Para cada registro eliminado Seleccionar grado_dominio de
-
Help: VA01/2 - Shipping tab - Tolerance Fields not Maintainable.
These fields are not maintainable in VA01 and VA02 in our ECC 6.0 system. We can't find in config where to allow and open these fields up to make them so the users can change the values of these two fields (over and under tolerance on the shipping ta