What is a Nested Query
Hi,
What is a nested query? Can anyone give me an example of how to create a nested query? Please expain me in detail with an example?
Thanks
Rani
Hi,
nested query is like one querys result is used as a input to second query.it is sort of a replacement path char variable filled by a query result is used for a char restriction in one query. Restriction is somewhat like Top N. Returned set of values is used for a restriction in the 2nd query.
Assume that in Query X, a characteristic A returns values 1,2,3. (Master data of A may be 1,2,3,4.....)
In another Query Y, you want to restrict char A to only those values that are returned in Query X, in our example its 1,2 & 3. To achieve this, you will create a replacement path variable on char A in Query Y, in the process it will ask you to give the query name, which will be Query X
For nested "If "condition in Bex Formula's:
http://help.sap.com/saphelp_nw2004s/helpdata/en/23/17f13a2f160f28e10000000a114084/frameset.htm
Regards
CSM Reddy
Similar Messages
-
Using nested query to avoid repeated object traversal
Hi everyone,
My SQL is still very basic, hopefully this is not a dumb question ;-)
I have a table with a single spatial column of type SDO_GEOMETRY:
SQL> desc WITHIN_POINT_DISTANCE_TAB
Name Null? Type
POINT MDSYS.SDO_GEOMETRYin which I store only single point geometries. I discovered that using the min/max SQL operators to get the combined extend of my points is faster than using SDO_TUNE.EXTEND_OF:
SQL> select min(e.point.sdo_point.x) min_x, max(e.point.sdo_point.x) max_x, min(e.point.sdo_point.y) min_y, max(e.point.
sdo_point.y) max_y from WITHIN_POINT_DISTANCE_TAB e;
MIN_X MAX_X MIN_Y MAX_Y
-44.700001 737.400024 -23.870001 1094.83008
Elapsed: 00:00:00.01but it bothers me a bit to repeat e.point.sdo_point 4 times in the above (what can I say, I'm a developer ;-) So I thought I could use a nested query to select all the SDO_POINT_TYPE sdo_point's and refer it using a p alias, and be able to simplify the query to:
SQL> select min(p.x), min(p.y), max(p.x), max(p.y) from (select t.point.sdo_point from WITHIN_POINT_DISTANCE_TAB t) p;
select min(p.x), min(p.y), max(p.x), max(p.y) from (select t.point.sdo_point from WITHIN_POINT_DISTANCE_TAB t) p
ERROR at line 1:
ORA-00904: "P"."Y": invalid identifierBut obviously this is incorrect, yet I'd like to understand what I'm missing here.
I posited that maybe the sub-query can't return an object member and needs to return a column, but that doesn't appear to be the case:
SQL> select min(p.sdo_point.x), min(p.sdo_point.y), max(p.sdo_point.x), max(p.sdo_point.y) from (select t.point from WIT
HIN_POINT_DISTANCE_TAB t) p;
select min(p.sdo_point.x), min(p.sdo_point.y), max(p.sdo_point.x), max(p.sdo_point.y) from (select t.point from WITHIN_P
OINT_DISTANCE_TAB t) p
ERROR at line 1:
ORA-00904: "P"."SDO_POINT"."Y": invalid identifierCan someone please explain why the nested query approach fails as written above?
More generally, is it a bad idea to go for a nested query just for syntactic reasons? Are there performance implications going the nested query route above? (I actually wanted to see the perf. implications experimentally, but since it fails I can't...)
Any insight would be appreciated. Thanks, --DDThank you Peter. I now understand that I need to alias the column in addition to the table (the latter only because I traverse objects which require table aliases).
SQL> select min(t.p.x), min(t.p.y), max(t.p.x), max(t.p.y) from
2 (select nt.point.sdo_point p from WITHIN_POINT_DISTANCE_TAB nt) t;
MIN(T.P.X) MIN(T.P.Y) MAX(T.P.X) MAX(T.P.Y)
-44.700001 -23.870001 737.400024 1094.83008
Elapsed: 00:00:00.01Performance-wise it looks similar, but I need to test on a bigger table because it's too fast with 10K points to show differences. Overall it doesn't look that using the nested query syntax makes the query more readable once all pieces to make it work are there.
Thanks again, --DD
PS: Just aliasing the column and not the outer table fails:
SQL> select min(p.x), min(p.y), max(p.x), max(p.y) from (select nt.point.sdo_point p from WITHIN_POINT_DISTANCE_TAB nt);
select min(p.x), min(p.y), max(p.x), max(p.y) from (select nt.point.sdo_point p from WITHIN_POINT_DISTANCE_TAB nt)
ERROR at line 1:
ORA-00904: "P"."Y": invalid identifier -
Nested query in FROM clause causes 'SQL Command not properly ended' error
SELECT sj.job_id AS job_id, 'STATUS_AWAITING_PREPARATION' AS job_status, sjr.email_sys_attach_filename AS attach_filename, sje.emailaddr as emailaddr_lastsentto
FROM arsnd_jobs sj, (SELECT emailaddr from ARSND_JOB_EMAILS where job_id=sj.job_id AND ROW_NUM=1) as SJE, ARSND_JOB_QUEUE sjq,ARSND_JOB_RECIPIENTS sjr
WHERE sj.job_id=sjq.job_id and sj.job_id=sjr.job_id
AND sjq.PROCESSING_STATE=0
ORDER BY sj.created
I don't see anything wrong with the above query, it fails with 'SQL Command not properly ended'.
If I remove the usage of the nested query in the FROM clause, then it doesn't give that error. Please advice what I'm doing wrong.Pls try
SELECT sj.job_id AS job_id, 'STATUS_AWAITING_PREPARATION' AS job_status, sjr.email_sys_attach_filename AS attach_filename, sje.emailaddr as emailaddr_lastsentto
FROM arsnd_jobs sj, (SELECT emailaddr from ARSND_JOB_EMAILS where job_id=sj.job_id AND ROW_NUM=1) SJE, ARSND_JOB_QUEUE sjq,ARSND_JOB_RECIPIENTS sjr
WHERE sj.job_id=sjq.job_id and sj.job_id=sjr.job_id
AND sjq.PROCESSING_STATE=0
ORDER BY sj.created
I have removed the 'as' clause you used for alias of the subquery. It should work fine now..... -
what is the diference between char dat type and n char dara type.
what is nested query and give me one examplewhat is the diference between char dat type and n char dara type.They have in common that you'd rather want to use (N)VARCHAR2 instead....
(Totally unrelated) example:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6349391411093#tom2648420300346089448
Quoting last sentence:
"sigh, wish they would have used a varchar.... if you do the above with a as a varchar2 instead of a stupid char (no one uses char, not if they know any better).... "
Regarding nested table:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:8135488196597 -
I am trying to rewrite the following query without using a
nested query:
select date_r,value
from indices
where date_r = (select max(date_r) from indices)
Is there any way to do this?
Thanks in advance,
ShefaliIt depends what version of Oracle you are on, I suppose.
You could do ..
select date_r,value
from (select date_r,value from indices order by date_r desc)
where rownum = 1
With an index on date_r (called idx_date_r) you could do ...
select /*+ index_desc(indices idx_date_r) */ date_r,value
from indices where rownum = 1 -
How to do a Nested Query ?
I have three Tables Student, Courses, Marks
Table : Student
Columns
StudentID <PK>
First Name
Last Name
Table : Grades
Columns
StudentID <FK>
Grade
Table : Courses
Columns
StudentID <FK>
CourseID
CourseDesc
Now to get all the course descriptions which this particular student is taking based on the StudentID we do something like this :
SELECT c.courseDesc
FROM Courses c, Student s
WHERE s.StudentID = '100'
AND s.StudentID = c.StudentID
The above will work
But If I need to do it in nested query how can I do it : Something like
SELECT * FROM
SELECT c.courseDesc
FROM Courses c, Student s
AND s.StudentID = c.StudentID
WHERE s.StudentID = '100'
Thanks for the help.
Harsimratoops,try this...
SELECT * FROM (
SELECT s.StudentID,c.courseDesc
FROM Courses c, Student s
WHERE s.StudentID = c.StudentID)
WHERE StudentID = '100';
SQL> select * from
2 (select e.ename,d.deptno from test_dept d,test_emp e where e.deptno = d.deptno)
3 where deptno = 10;
ENAME DEPTNO
BLAKE 10
CLARK 10
KING 10
MILLER 10
SQL> -
What is a pre query and in what circumstances it is used?
Please explain what is a pre query in BW mean,and when is it used...thank you for your answers...
Hi,
There is also a possibility to feed a variable with replacement path with a query result and use this variable for restriction in another query:
http://help.sap.com/saphelp_nw04s/helpdata/en/cf/579b3c494d8e15e10000000a114084/frameset.htm
Best regards,
Eugene -
A simple query in My SQL what is the similer query for that in Oracle ???
hello friends
In My Sql if i have 1000 records in a table and i want to get the records from 400 to 550 then it is posible by giving the following query
Select * from Table a , table b where condition "List 400,550" gives the records from 400 to 550
what is the coresponding query for this in oracle database
any one help me pls
mail me to [email protected]Genericly, if you want records N through M from a SELECT statement, there's a wonderful article on asktom.oracle.com
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:127412348064
Justin -
Nested query in BPEL JDeveloper
Hi,
Can anyone help me with nested query writing in BPEL (JDeveloper)
the query is :
SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
FROM ITEM_SUPP_COUNTRY_DIM
WHERE ITEM= <Level1 item>
AND DIM_OBJECT= (SELECT CASE_NAME FROM ITEM_SUPPLIER WHERE ITEM=<Item> AND PRIMARY_SUPP_IND = ‘Y')
Please help me with the steps.
Many thanksHi,
For the following query:
SELECT S.STORE, S.STORE_NAME, A.ADD_1, A.ADD_2, A.ADD_3, A.CITY,A.STATE, A.POST, A.COUNTRY_ID, A.CONTACT_PHONE, A.CONTACT_NAME,S.STORE_OPEN_DATE, S.STORE_CLOSE_DATE, S.REMODEL_DATE, S.TRANSFER_ZONE,S.DISTRICT,S.STORE_TYPE
FROM STORE S, ADDR A
WHERE S.STORE= #store
AND to_char(S.STORE) = #keyValue1
AND A.MODULE = #module
AND A.ADDR_TYPE = #type
AND A.PRIMARY_ADDR_IND=#addrType
the DB adapter shows this xml:
<?xml version = '1.0' encoding = 'UTF-8'?>
<xs:schema targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/WMSStoreDataLookUp" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/WMSStoreDataLookUp" elementFormDefault="qualified" attributeFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="WMSStoreDataLookUpInput" type="WMSStoreDataLookUpInput"/>
<xs:complexType name="WMSStoreDataLookUpInput">
<xs:sequence>
<xs:element name="store" type="/><br /><br /> <xs:element name="keyValue1" type="/>
<xs:element name="module" type="/><br /><br /> <xs:element name="type" type="/>
<xs:element name="addrType" type="/><br /><br /> </xs:sequence><br /><br /></xs:complexType><br /><br /><xs:element name="WMSStoreDataLookUpOutputCollection" type="WMSStoreDataLookUpOutputCollection" nillable="true"/><br /><br /><xs:complexType name="WMSStoreDataLookUpOutputCollection"><br /><br /><xs:sequence><br /><br /><xs:element name="WMSStoreDataLookUpOutput" type="WMSStoreDataLookUpOutput" minOccurs="0" maxOccurs="unbounded"/><br /><br /></xs:sequence><br /><br /></xs:complexType><br /><br /><xs:complexType name="WMSStoreDataLookUpOutput"><br /><br /><xs:sequence><br /><br /><xs:element name="S_STORE" type="xs:decimal" nillable="true"/><br /><br /><xs:element name="S_STORE_NAME" type="xs:string" nillable="true"/><br /><br /><xs:element name="A_ADD_1" type="xs:string" nillable="true"/><br /><br /><xs:element name="A_ADD_2" type="xs:string" nillable="true"/><br /><br /><xs:element name="A_ADD_3" type="xs:string" nillable="true"/><br /><br /><xs:element name="A_CITY" type="xs:string" nillable="true"/><br /><br /><xs:element name="A_STATE" type="xs:string" nillable="true"/><br /><br /><xs:element name="A_POST" type="xs:string" nillable="true"/><br /><br /><xs:element name="A_COUNTRY_ID" type="xs:string" nillable="true"/><br /><br /><xs:element name="A_CONTACT_PHONE" type="xs:string" nillable="true"/><br /><br /><xs:element name="A_CONTACT_NAME" type="xs:string" nillable="true"/><br /><br /><xs:element name="S_STORE_OPEN_DATE" type="xs:dateTime" nillable="true"/><br /><br /><xs:element name="S_STORE_CLOSE_DATE" type="xs:dateTime" nillable="true"/><br /><br /><xs:element name="S_REMODEL_DATE" type="xs:dateTime" nillable="true"/><br /><br /><xs:element name="S_TRANSFER_ZONE" type="xs:decimal" nillable="true"/><br /><br /><xs:element name="S_DISTRICT" type="xs:decimal" nillable="true"/><br /><br /><xs:element name="S" type="xs:string" nillable="true"/><br /><br /><xs:element name="A_PRIMARY_ADDR_IND__addrType" type="xs:string" nillable="true"/><br /><br /></xs:sequence><br /><br /></xs:complexType><br /><br /></xs:schema><br /><br /><br /><br />Please, look at the last few lines of XML and let me know if this is correct.. -
Count(*) with nested query
Hi,
I have a question about the count(*) with nested query.
I have a table T1 with these columns:
C1 number
C2 number
C3 number
C4 number
C5 number
(The type of each column is not relevant for the example.)
This query:
select C1, C2, C3, C4
from T1
group by C1, C2
it's not correct becausa C3 and C4 are not columns specified in the GROUP BY expression.
If if run this query:
select count(*)
from (select C1, C2, C3, C4
from T1
group by C1, C2)
I haven't an error message (the result is correctly the number of records).
Why?
Thanks.
Best regards,
LucaBecause you are just selecting count(*) and none of the columns from the subquery, Oracle is optimising it by ignoring the selected columns and just running the sub query with the group by columns. I know it seems odd, but if you take a basic example:
SQL> ed
Wrote file afiedt.buf
1 select count(*)
2 from (select empno, sal, mgr, deptno
3 from emp
4* group by deptno)
SQL> /
COUNT(*)
3... all columns but deptno are ignored
... but if you include one of the other columns, even if you group by that column...
SQL> ed
Wrote file afiedt.buf
1 select count(*), empno
2 from (select empno, sal, mgr, deptno
3 from emp
4 group by deptno)
5* group by empno
SQL> /
group by empno
ERROR at line 5:
ORA-00979: not a GROUP BY expression
SQL>... the error returns, because you're forcing oracle to include the column in the subquery. -
Hi Friends,
if we run a query,what all happens in background/what are phases of query processesing.?
Many thanks
ShashikalaIt has to go through
Parsing-on this stage it perform basic check on code (T-SQL,
Binding(Algebrizer Stage)-on this stage does more parsing and perform query tree,
Optimize- on this stage take query tree from Binding and parsing and find a better way to return the result that you need so cost might apply here and then
Execute
To know about transaction Log we have to know first how Transaction log file internally works: when you are trying to make change in data as Insert, Update, Delete requests
from applications using T-SQL or on object explorer, SQL Server will load (load) to the corresponding page data memory where we call this memory area as DATA CACHE. Then the data in the data cache are changed which is also known as known as DIRTY PAGE.
Next all changes we made by running query will be recorded in the transaction log file so they called the write-ahead log. At final stage, a process known as CHECK POINT PROCESS will check and write all the transaction has been committed AND completed to your
hard drive by flushing the page.
So simply put here are the steps
Data modification sent by application
Data pages are located in or read into, cache and modified
Modification is recorded in transaction log on DISK
Checkpoint writes committed transactions to database
I hope this helps a bit in answering your question good luck. -
Error in making left outer join to a nested query
i am writing this query getting error here i am using nested query with that i am making join it is giving error
SQL
SELECT
* FROM IVItem INNER JOIN
IVPackSize_Mst ON IVItem.PackSizeID = IVPackSize_Mst.Id
left outer join IvItemGenericLink on IvItemGenericLink.itemID=IVItem.Id
Select GenericId from
IvItemGenericLink where ItemID=IVItem.Id and rownum <=1
)x
and x on IvItemGenericLink.GenericId=x.GenericId;
Error report:
SQL Error: ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
give me and suggestioni am using left outer join at virtual table say x your gave me its equivalent
EXISTS (SELECT 1 FROM IvItemGenericLink G
WHERE G.ITEMID =V.ID
AND G.GenericId = L.GenericId)-----its i guess inner join
i am not confirmed that why iam asking this i guess i have to use this
as i use keyword inner join for inner join and for left join i use
left outer join
EXISTS (SELECT 1 FROM IvItemGenericLink G
WHERE G.ITEMID =V.ID
AND G.GenericId(+) = L.GenericId)-----its i guess left outer join
left outer join
Select GenericId from
IvItemGenericLink where ItemID=IVItem.Id and rownum <=1
)*x*
IvItemGenericLink.GenericId=x.GenericId
-------------------Statement U Gave in this--------------------------------------------------------------------------
SELECT *
FROM IVITEM V, IVPACKSIZE_MST M , IVITEMGENERICLINK L,
WHERE V.PACKSIZEID = M.ID
AND V.ID = L.ITEMID (+)
AND EXISTS (SELECT 1 FROM IvItemGenericLink G
WHERE G.ITEMID =V.ID
AND G.GenericId = L.GenericId)
-------------------Statement U Gave in this--------------------------------------------------------------------------
is this equivalent to left outer join
*AND EXISTS (
SELECT 1 FROM IvItemGenericLink G*
WHERE G.ITEMID =V.ID
*AND G.GenericId = L.GenericId
please tell me this in this regard -
What is a Pre-query?
Regards,Check if these links help:
http://help.sap.com/saphelp_erp2005vp/helpdata/en/95/b27f425b595551e10000000a1550b0/frameset.htm
http://help.sap.com/saphelp_nw04s/helpdata/en/cf/579b3c494d8e15e10000000a114084/frameset.htm
Pre-Query -
What is Varray,Nested tables,Collections,Pragma?
Hi,
what is Varray,Nested tables,Collections,Pragma?
and in Which Situations will We Use this?.
Anyone having any dea regarding this?http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm
http://awads.net/wp/2006/03/01/pragmatism-in-oracle-plsqlKhurram -
Nested query / Rank in ODI 10g?
How can be an nested query with analytical function (RANK() OVER) can be implemented in ODI 10g without using an external view?
SELECT field1, field2, field3, field4, field5, field6, field7
FROM
(SELECT
RANK() OVER (PARTITION BY table1.field1, table1.field2, table1.field3 ORDER BY table1.field4 , table1.field5) alias_rank,
field1, field2, field3, field4, field5, field6, field7
FROM table1
) subset_alias
WHERE subset_alias.alias_rank=10)You should get your answers from here
http://www.business-intelligence-quotient.com/?tag=oracle-data-integrator-subqueries
Maybe you are looking for
-
How can i see my file on iphone?
I want to see my document on iphone, do I have to download an app?
-
Problem in calling a web service hosted on tomcat from BEA WebLogic portal
Hi, I have a wsdl file for my web service which is hosted on apache tomcat 5.5(running on port : 8080). The contents of the wsdl file are- *<?xml version="1.0" encoding="UTF-8"?>* *<wsdl:definitions targetNamespace="http://soa.tutorials.serg.edu" xml
-
I've used PowerPoint for the past 10+ years, and only have recently converted to Keynote '08 -- so my familiarity is heavy in PowerPoint not Keynote, so forgive my naivety. I think I have discovered a dilemma: When I have an external display hooked u
-
[ISE + CWA] Redundant Guestportal
Hello Community, I try to configure a redundant guest access with 2 ISE und 2 guests anchors. ISE Management and the sponsor portal are connected to eth0 (gig0) with hostname ise1.mydomain.com (ise2.mydomain.com for 2nd ISE). Eth0 is reachable from c
-
How to use routing service property value in xsl
Hi All, I need to use routing service's property value in xsl. I created routing service in esb project. after routing rules, thare is properties. In properties I added name as "propval" and value as "required". I need to use value of propval in one