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 thanks

Hi,
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>
&lt;xs:element name="store" type="/&gt;<br /><br /> &lt;xs:element name="keyValue1" type="/&gt;
&lt;xs:element name="module" type="/&gt;<br /><br /> &lt;xs:element name="type" type="/&gt;
&lt;xs:element name="addrType" type="/&gt;<br /><br /> &lt;/xs:sequence&gt;<br /><br />&lt;/xs:complexType&gt;<br /><br />&lt;xs:element name="WMSStoreDataLookUpOutputCollection" type="WMSStoreDataLookUpOutputCollection" nillable="true"/&gt;<br /><br />&lt;xs:complexType name="WMSStoreDataLookUpOutputCollection"&gt;<br /><br />&lt;xs:sequence&gt;<br /><br />&lt;xs:element name="WMSStoreDataLookUpOutput" type="WMSStoreDataLookUpOutput" minOccurs="0" maxOccurs="unbounded"/&gt;<br /><br />&lt;/xs:sequence&gt;<br /><br />&lt;/xs:complexType&gt;<br /><br />&lt;xs:complexType name="WMSStoreDataLookUpOutput"&gt;<br /><br />&lt;xs:sequence&gt;<br /><br />&lt;xs:element name="S_STORE" type="xs:decimal" nillable="true"/&gt;<br /><br />&lt;xs:element name="S_STORE_NAME" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="A_ADD_1" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="A_ADD_2" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="A_ADD_3" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="A_CITY" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="A_STATE" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="A_POST" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="A_COUNTRY_ID" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="A_CONTACT_PHONE" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="A_CONTACT_NAME" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="S_STORE_OPEN_DATE" type="xs:dateTime" nillable="true"/&gt;<br /><br />&lt;xs:element name="S_STORE_CLOSE_DATE" type="xs:dateTime" nillable="true"/&gt;<br /><br />&lt;xs:element name="S_REMODEL_DATE" type="xs:dateTime" nillable="true"/&gt;<br /><br />&lt;xs:element name="S_TRANSFER_ZONE" type="xs:decimal" nillable="true"/&gt;<br /><br />&lt;xs:element name="S_DISTRICT" type="xs:decimal" nillable="true"/&gt;<br /><br />&lt;xs:element name="S" type="xs:string" nillable="true"/&gt;<br /><br />&lt;xs:element name="A_PRIMARY_ADDR_IND__addrType" type="xs:string" nillable="true"/&gt;<br /><br />&lt;/xs:sequence&gt;<br /><br />&lt;/xs:complexType&gt;<br /><br />&lt;/xs:schema&gt;<br /><br /><br /><br />Please, look at the last few lines of XML and let me know if this is correct..

Similar Messages

  • Reg: SQL select Query in BPEL process flow

    <p>
    Hi,
    I am suppose to execute a SQL select query (in BPEL Process flow) as mention below in JDeveloper using Database adapter.
    </p>
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE ITEM= &lt;xyz&gt;
    </p>
    <p>
    AND OBJECT= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=&lt;xyz&gt; AND SUPP_IND = &lsquo;Y')
    <strong>Now my question is:
    1.</strong> What does this "*" refer to in the query and how can I retrieve the value of LENGTH*WIDTH* HEIGHT from the query where LENGTH,WIDTH and HEIGHT are the individual field in the table.
    2.What does this " AS" refer to? If " ITEM_CUBE " is the alies for the table name "ITEM" to retrieve the value, then query shoud be evaluated as
    </p>
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE <strong>ITEM_CUBE.ITEM</strong>= &lt;xyz&gt;
    </p>
    <p>
    AND <strong>ITEM_CUBE.OBJECT</strong>= (SELECT CASE_NAME FROM CUBE_SUPPLIER WHERE ITEM=&lt;xyz&gt; AND SUPP_IND = &lsquo;Y')
    Is my assumption correct?
    Please suggest asap.
    Thanks...
    </p>
    <p>
    </p>

    Hi
    Thank for your reply!
    I have a nested select query which performs on two different table as shown below:
    <p>
    SELECT LENGTH, WIDTH, HEIGHT, WEIGHT,
    </p>
    <p>
    LENGTH*WIDTH* HEIGHT AS ITEM_CUBE
    </p>
    <p>
    FROM CUBE
    </p>
    <p>
    WHERE ITEM= &lt;abc&gt;
    </p>
    <p>
    AND OBJECT= (SELECT NAME FROM SUPPLIER WHERE ITEM=&lt;Item&gt; AND SUPP_IND = &lsquo;Y')
    I am using DB adapter of Oracle JDeveloper in BPEL process flow, where I can able to select only one master table in DB adapter say SUPPLIER and its attributes at a time.But as per my requirment I need to select both the table (CUBE and SUPPLIER) in a single adapter to execute my query.
    It can be achievable by using two DB adapter , One to execute the nested query and another to execute the main qyery considering value of nested query as a parameter.But I want to achieve it by using a single one.
    Am I correct with my concept?
    Please suggest how to get it ?
    </p>
    Edited by: user10259700 on Oct 23, 2008 12:17 AM

  • 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.
    Harsimrat

    oops,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>

  • 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, --DD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Thank 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

  • Complex SQL Query in BPEL DB Adapter

    Hi,
    Is it possbile to write a complex query in BPEL DB Adapter using "Custom SQL Query"?
    I would like to write an IF ELSE condition in the DB Adapter similar what is given below..
    IF((SELECT COUNT(*) FROM F5898001 WHERE CT58SRCNME = 'CA_TEST' AND CTJOBNAME = '12345' AND CTEDBT = 'EDBT' AND CTEDSP = 'B') < 1)
    BEGIN
    insert into f5898001 (CTJOBNAME,CTEDSP,CTEDBT,CT58SRCNME) VALUES (#jobname, #edsp, #edbt, #srcnme)
    END.

    In a single pass no.
    You could use a DB link to perform select and return result to BPEL process variable. Put a switch decision depending on result in variable that calls a DB Adapter to perform the insert.
    Wouldn't be in a single transaction and not very elegant, but might be a way round.

  • 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,
    Luca

    Because 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.

  • How to use Query Builder in JDeveloper?

    I am not able to use Query Builder with JDeveloper version 11g 2.
    The online documentation about Query Builder:
    http://docs.oracle.com/cd/E35521_01/user.111230/e17455/db_tools.htm#OJDUG2380
    "To use Query Builder:
    Open the SQL Worksheet.
    Right-click and choose Query Builder."
    But when I right-click on the SQL Worksheet, there is no menu item "Query Builder".
    Does the documentation belong to a different version of JDeveloper?
    Edited by: Ralf_user4689599 on 06.05.2013 15:40

    all features of 11.1.2.3.0 are installed.
    It makes no difference wether I start studio developer or database developer role.
    There's no query builder in the context menu of the sql worksheet.

  • 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 suggestion

    i 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

  • Query on bpel.config.OneWayDelivery Property

    Hello,
    I have a query on bpel.config.OneWayDelivery Property.
    Scenario : In case of any error in BpelProcess A , it will call BpelProcess B .So BpelProcessB will be called in the catchAll branch of Process A. After calling Process B, i am throwing a fault in Process A to rollback process A (as there is a DB adpater in it which i want to roll back). To invoke Process B in a separate transaction i set the bpel.config.transaction to requires new in the component section of composite.xml of process B. Please not Process B is ASynchronous process. Now :
    Case 1: By setting only bpel.config.transaction property to 'requiresnew'.
    Process A gets error, it calls Process B and it itself get rolledback (because of throw activity after a call to Process B). Now in the instance of Process A i am not able to see the trace of Process B. Only Process B name is appearing, also Process B didn't get executed at all or might be rolledback along with process A (not sure on this).
    Case 2: By setting only bpel.config.transaction property to 'requiresnew' and  bpel.config.OneWayDelivery property to 'sync'.
    In this case everything works fine like Process A call Process B in case of Error. Process A get rolledback successfully and i am able to see the trace of Process B as it get executed successfully.
    Questions :
    In case1 though i have set the transaction=requiresnew, why Process B is not getting executed and i am not able to see the trace of it.Ideally Process B should get executed in a seperate transaction. While in Case2, everything works fine. So what exactly happening after placing 'OnewayDelivery' Property, that it started working.
    I have went through the documents on 'OnewayDelivery', but i didn't get the clear idea corresponding to my scenarios explained above.
    Can anyone please explain on how exactly 'OnewayDelivery' property works.
    Thanks.

    So,
    For Case 1 : When Process B is getting executed in a separate Thread and Transaction , then when process A is getting rolled back why B is also getting rolled back as it's in different thread althgether.
    3) For Case2 : Please clear my following understanding :
    When we set the value to 'sync' for process B, then B will act like a synchronous process(ideally it Async), and will get committed after the it's execution. Because of this, even if A is getting rolled back, B will not get rolledback because it is already committed. For case 1:
    By calling process B, an invocation message is being insert into the dehydration store. That causes process B to be created as a new thread/transaction.
    When you perform rollback->the new transaction that was made following the new thread, is being rollback among the rest of your process transaction(the rollback causes the message not to be save and for that you can't see new instance).
    For case 2:
    By calling process B, only a new transaction is being creating, and invocation message is not being insert into the dehydration store.
    So actualy, you have 1 thread and 2 transactions, and you are telling your process(thread) to rollback only the current transaction and not the new one (process A not owns the new transaction).
    2) You mentioned if we are calling Process B with No Rollback. How to call B with No Rollback? Is there any property like that? It was just an example. Forget about it.
    I hope it answered you questions...
    Arik

  • BPEL JDeveloper 10.1.2

    Hi,
    When a wsdl is openend in BPEL JDeveloper, the structure window will show all the definitions such as types, message, portType, partnerLinkType etc.
    When you right click on these nodes you get a popup menu with some options.
    For example, right clicking on element node gives 'Insert before element', 'Insert After Element' options. But sometimes this popup menu option doesn't show these items. Is this a configuration issue or a bug in JDeveloper?
    Thank you for you help!
    -- DA.

    We currently are not in a position to migrate to the new version as we have a number of processes.
    Is there a document where all the features of JDeveloepr BPEL Designer is documented?
    Thanks,
    -- DA

  • 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

  • Stimulate Nested query in OBI

    Can i stimulate nested query in OBI?\
    Thanks
    Bhupendra Gupta

    You can also use the obiee logical sql.
    Here an example of densification where you can see that you can use subquery.
    http://gerardnico.com/weblog/2009/05/12/densification-with-obiee-logical-sql-spare-to-dense-data/
    Success
    Nico

  • Nested query loops

    If you have nested query loops (<cfloop
    query="qA"><cfloop query="qB"> qA vars in here
    </cfloop></cfloop>), is it possible to carry the vars
    from qA into the qB loop.
    Not sure if this makes sense, but any time i have nested
    query loops, i can't access the outer loops vars.

    Use a different index variable for each loop. Use complete
    syntax, ie queryname.fieldname[rownumber] for each query
    variable.

  • Executing nested query contains ORDER BY:Help Needed

    I have a database in ORACLE 8.0 enterprise
    edition in HP-UX. I am trying to execute the following query
    "select * from ( select * from temptable order by value desc) where rownum < 5"
    and I am getting the following error
    "missing right parenthesis"
    This syntax is given in the Oracle user guide
    under sql commands section and it is not
    working.
    Similar query is working on Oracle 8.1 running on Win NT.
    Does any body throw some light.
    Thanks in advance
    -raj

    Your query works fine in Oracle 8i:
    SELECT *
    FROM (SELECT *
    FROM temptable
    ORDER BY value DESC)
    WHERE ROWNUM < 5;
    However, prior to Oracle 8i, in Oracle 8.0, it is not allowed to have an ORDER BY clause within a nested query. So, in Oracle 8.0, a query like the above cannot work. However, the following, with the ORDER BY clause in the outer query will work:
    SELECT *
    FROM temptable a
    WHERE 5 >=
    (SELECT COUNT (*) + 1
    FROM temptable b
    WHERE b.value > a.value)
    ORDER BY a.value DESC;
    null

  • 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.....

Maybe you are looking for