CORRELATED SUB QUERY IN OBIEE

Hi Experts,
How to achieve correlated sub query in OBIEE
Example for correlated sub query is here:
SELECT
HR_EMPLOYEE_DIM.EMPLID,
HR_EMPLOYEE_DIM.NAME,
HR_EMPLOYEE_DIM.JOBCODE_CD,
HR_EMPLOYEE_DIM.JOBCODE_DESC,
FROM
HR_EMPLOYEE_DIM,
EMPLOYEE_ACTION_FACT
WHERE
( EMPLOYEE_ACTION_FACT.HR_EMPLOYEE_KEY=HR_EMPLOYEE_DIM.HR_EMPLOYEE_KEY )
AND
( to_char(EMPLOYEE_ACTION_FACT.PS_EFF_DT,'yyyymmdd') || EMPLOYEE_ACTION_FACT.PS_EFF_SEQ=
(SELECT MAX(TO_CHAR(PS_EFF_DT,'yyyymmdd')|| PS_EFF_SEQ)
FROM
EMPLOYEE_ACTION_FACT EAF1,
HR_EMPLOYEE_DIM HED1
WHERE EAF1.HR_EMPLOYEE_KEY = HED1.HR_EMPLOYEE_KEY
AND HED1.PS_EMPLID = HR_EMPLOYEE_DIM.PS_EMPLID
Thanks
Naresh
Edited by: Naresh Meda on Dec 2, 2008 5:52 AM

But I want to pass presentation variable for the second query.
Regards
Naresh
Edited by: Naresh Meda on Dec 2, 2008 10:27 PM

Similar Messages

  • Correlated Sub Query

    Deal All,
    Please help me to know list of Drawback/Limitation of Corellated Subquery.
    i want to Optimize the correlated sub Query.
    Thanks,
    Dinesh Babu
    9818783322

    See:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:3167884300346662300
    It would be nice to know your database version.
    It would be nice to know what query you're executing
    It would be nice to see an execution plan
    It would be nice if you'd first read the SQL and PL/SQL FAQ, especially:
    SQL and PL/SQL FAQ
    and
    *3. How to improve the performance of my query? / My query is running slow*.
    When your query takes too long...
    How to post a SQL statement tuning request
    SQL and PL/SQL FAQ

  • Correlated sub-query/outer join problem

    Hi,
    I have a problem similar to this one (Outer join with correlated subquery but I'm struggling to find a solution for mine!
    The following query works OK unless there is no entry in room_prices, so I need to outer join somehow to that table otherwise it doesn't return any rows.
    The main difference between the query in the other thread and mine is that mine has an extra table (bookings b) in the sub-query, which is complicating things a bit.
    select b.book_from,
         b.book_to,
         b.flat_rate,
         nvl(c.discount,0),
         p.hourly,
         p.half_day,
         p.daily,
         p.discountable,
         p.surcharge,
         l.evening_start,
         nvl(b.full_day,'N')
    from booking.bookings b,
    booking.customer c,
    booking.room_prices p,
    booking.rooms r,
    booking.location l
    where b.id = 9272
    and c.id = b.customer
    and b.room = p.room
    and b.room = r.id
    and r.loc = l.id
    and p.from_date =
    select max(p2.from_date)
    from booking.room_prices p2
    where p2.room = p.room
    and p2.from_date < b.book_from
    Could anyone suggest a way to re-write the query so that it is outer joined to room_prices?
    Thanks,
    Hazel

    Thanks for both of your responses.
    Unfortunately your suggestion didn't work Dmytro - still no rows are returned.
    Here are some table creation scripts and test data to insert:
    CREATE TABLE BOOKINGS
    ID NUMBER NOT NULL,
    ROOM NUMBER NOT NULL,
    CUSTOMER NUMBER NOT NULL,
    BOOK_FROM DATE NOT NULL,
    BOOK_TO DATE NOT NULL,
    CONFIG VARCHAR2(24) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DELEGATES NUMBER,
    NARRATIVE VARCHAR2(256),
    CONTACT_DETAILS VARCHAR2(400),
    CONFIRMED VARCHAR2(1),
    CANC_REASON NUMBER,
    FULL_DAY VARCHAR2(1),
    FLAT_RATE NUMBER,
    STANDBY NUMBER,
    TOTAL_STANDBY_TIME DATE,
    PRE_STANDBY_TIME DATE,
    PRE_STANDBY NUMBER,
    GL_CODE VARCHAR2(20)
    CREATE TABLE CUSTOMER
    ID NUMBER NOT NULL,
    CUSTOMER VARCHAR2(160) NOT NULL,
    CONTACT_ADDRESS VARCHAR2(240),
    CONTACT_TELEPHONE VARCHAR2(20),
    CONTACT_EMAIL VARCHAR2(160),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    DISCOUNT NUMBER(5,2),
    CUST_TYPE VARCHAR2(1),
    CONTACT_FAX VARCHAR2(20),
    DEBTOR_NO VARCHAR2(20),
    BC_CONTACT VARCHAR2(64)
    CREATE TABLE ROOMS
    ID NUMBER NOT NULL,
    LOC NUMBER NOT NULL,
    NAME VARCHAR2(160) NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    ACTIVE VARCHAR2(1),
    ROOM_DESC VARCHAR2(2000)
    CREATE TABLE LOCATION
    ID NUMBER NOT NULL,
    NAME VARCHAR2(240) NOT NULL,
    ADDRESS VARCHAR2(240),
    PCODE VARCHAR2(8),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    CONF_RDF VARCHAR2(10),
    CLOSING VARCHAR2(5),
    EVENING_START VARCHAR2(5)
    CREATE TABLE ROOM_PRICES
    ROOM NUMBER NOT NULL,
    FROM_DATE DATE NOT NULL,
    HOURLY NUMBER(6,2),
    HALF_DAY NUMBER(6,2),
    DAILY NUMBER(6,2),
    DISCOUNTABLE VARCHAR2(1),
    CREATED_DATE DATE NOT NULL,
    CREATED_BY VARCHAR2(16) NOT NULL,
    UPDATED_DATE DATE,
    UPDATED_BY VARCHAR2(16),
    SURCHARGE NUMBER(6,2)
    Insert into bookings
    (ID, ROOM, CUSTOMER, BOOK_FROM, BOOK_TO, CONFIG, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, DELEGATES, NARRATIVE, CONTACT_DETAILS, CONFIRMED, FLAT_RATE, PRE_STANDBY_TIME, PRE_STANDBY)
    Values
    (9272, 7466, 4946, TO_DATE('10/25/2005 10:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('10/25/2005 13:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'Default', TO_DATE('10/27/2005 15:35:02', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', TO_DATE('10/27/2005 15:36:26', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 1, 'another meeting', 'Hazel', 'Y', 40, TO_DATE('10/25/2005 09:30:00', 'MM/DD/YYYY HH24:MI:SS'), 1800);
    Insert into customer
    (ID, CUSTOMER, CONTACT_ADDRESS, CONTACT_TELEPHONE, CREATED_DATE, CREATED_BY, CUST_TYPE, BC_CONTACT)
    Values
    (4946, 'Association of Teachers', 'Address', '0191 8887777', TO_DATE('09/22/2003 08:05:47', 'MM/DD/YYYY HH24:MI:SS'), 'Dataload', 'B', 'Miss Jones');
    Insert into rooms
    (ID, LOC, NAME, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, ACTIVE)
    Values
    (7466, 308, ' Counselling Room 1', TO_DATE('04/11/2005 10:55:33', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/22/2005 14:43:50', 'MM/DD/YYYY HH24:MI:SS'), 'HSIS0201', 'Y');
    Insert into location
    (ID, NAME, ADDRESS, PCODE, CREATED_DATE, CREATED_BY, UPDATED_DATE, UPDATED_BY, CONF_RDF, CLOSING, EVENING_START)
    Values
    (308, 'Business Centre', 'Address', 'NE30 1NT', TO_DATE('03/19/2003 13:07:35', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', TO_DATE('06/09/2005 11:17:09', 'MM/DD/YYYY HH24:MI:SS'), 'BJAC1906', 'BKCF_2', '22:30', '18:00');
    Thanks,
    Hazel

  • Using correlated sub-query in update stmt

    Hi,
    I just need a help to fine tune this below query. The following query is throwng connection reset error.
    UPDATE ftmmgr.RECON_TEMP RT SET PRCS_STAT_F =
    (CASE WHEN (SELECT COUNT(1) as count FROM ftmmgr.INVC_ITEM ii WHERE ii.INVC_SEQ_I = RT.INVC_SEQ_I) =
    (SELECT COUNT(1) as count FROM ftmmgr.RECON_TEMP rtr WHERE rtr.INVC_SEQ_I = RT.INVC_SEQ_I AND
    UPPER(TRIM(SLF_RECON_F)) = 'N' AND UPPER(TRIM(SRC_SYS_C)) = 'FTM')
    THEN 'F' ELSE 'O' END)
    Thanks in advance

    vasanthskr wrote:
    Hi,
    I just need a help to fine tune this below query. The following query is throwng connection reset error.
    UPDATE ftmmgr.RECON_TEMP RT SET PRCS_STAT_F =
    (CASE WHEN (SELECT COUNT(1) as count FROM ftmmgr.INVC_ITEM ii WHERE ii.INVC_SEQ_I = RT.INVC_SEQ_I) =
    (SELECT COUNT(1) as count FROM ftmmgr.RECON_TEMP rtr WHERE rtr.INVC_SEQ_I = RT.INVC_SEQ_I AND
    UPPER(TRIM(SLF_RECON_F)) = 'N' AND UPPER(TRIM(SRC_SYS_C)) = 'FTM')
    THEN 'F' ELSE 'O' END)
    Thanks in advanceNo database version provided?
    No table structures povided?
    No example data provided?
    No explanation as to what you're trying to achieve?
    As for tuning....
    No explain plans provided?
    No trace provided?
    No details of indexes or statistics, cardinality, selectivity or skew of data provided?
    Read these threads:
    [How to post a SQL statement tuning request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
    [When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
    It's also a good idea to provide a nicely formatted version of your code so people can read it, using {noformat}{noformat} tags around it...UPDATE ftmmgr.RECON_TEMP RT
    SET PRCS_STAT_F =
    (CASE WHEN (SELECT COUNT(1) as count
    FROM ftmmgr.INVC_ITEM ii
    WHERE ii.INVC_SEQ_I = RT.INVC_SEQ_I)
    =
    (SELECT COUNT(1) as count
    FROM ftmmgr.RECON_TEMP rtr
    WHERE rtr.INVC_SEQ_I = RT.INVC_SEQ_I
    AND UPPER(TRIM(SLF_RECON_F)) = 'N'
    AND UPPER(TRIM(SRC_SYS_C)) = 'FTM')
    THEN 'F'
    ELSE 'O'
    END)

  • Give the query  for  this requirement can we get it in correlated sub query

    i have to query avg(someinfo) group by dayofthemonth for last three days
    select someinfo from
    (select avg(someinfo)from table tab
    group by dayofdate1
    where exists(select * from table
    having max(date1)-tab.date1<3 )
    how can we group day of the date1
    someinfo date1
    10 28-jun-2006
    20 28-jun-2006
    30 29-jun-2006
    30 29-jun-2006
    10 30-jun-2006
    20 30-jun-2006
    30 1-july-2006
    40 1-july-2006
    30 2-july-2006
    40 2-july-2006
    i have to query avg(someinfo) group by day for last three days
    avg(someinfo) date1
    35 2-jun-2006
    35 1-july-2006
    15 30-june-2006
    here no need of union
    Message was edited by:
    user517983
    Message was edited by:
    user517983
    Message was edited by:
    user517983
    Message was edited by:
    user517983

    SQL> CREATE TABLE t_table
      2  AS
      3 (SELECT 10 day ,'28-jun-2006' ft FROM dual
      4  UNION
      5  SELECT 20,'28-jun-2006' FROM dual
      6  UNION
      7  SELECT 30,'29-jun-2006' FROM dual
      8  UNION
      9  SELECT 30,'29-jun-2006' FROM dual
    10  UNION
    11  SELECT 10,'30-jun-2006' FROM dual
    12  UNION
    13  SELECT 20,'30-jun-2006' FROM dual
    14  UNION
    15  SELECT 30,'1-jul-2006' FROM dual
    16  UNION
    17  SELECT 40,'1-jul-2006' FROM dual
    18  UNION
    19  SELECT 30,'2-jul-2006' FROM dual
    20  UNION
    21  SELECT 40,'2-jul-2006' FROM dual)
    22  .
    SQL> /
    Table created.
    SQL> DESC t_table
    Name                                                  Null?    Type
    DAY                                                            NUMBER
    FT                                                             VARCHAR2(11)
    SQL> SELECT * FROM t_table;
           DAY FT
            10 28-jun-2006
            10 30-jun-2006
            20 28-jun-2006
            20 30-jun-2006
            30 1-jul-2006
            30 2-jul-2006
            30 29-jun-2006
            40 1-jul-2006
            40 2-jul-2006
    9 rows selected.
    SQL> SELECT day,ft FROM (SELECT AVG(day) day,ft FROM t_table GROUP BY ft ORDER BY ft DESC)
      2  WHERE ROWNUM<=3;
           DAY FT
            15 30-jun-2006
            30 29-jun-2006
            15 28-jun-2006Khurram

  • Need help in correlated sub query logic

    Hi ,
    I have one procedure with cursor. I have given small part of the cursor as shown below .
    SELECT
      A.DAY_DATE,
      A.COUNTRY_CODE,
      A.INST_CODE,
      a.bra_code,
      a.cus_num,
      a.cur_code,
      a.led_code,
      a.sub_acct_code,
      (tra_amt * SPOT_RATE) pre_day_crnt_bal,
      t.mat_date,
      t.NEW_INT_RATE int_rate,
      t.DEB_CRE_IND int_chg_pai_ind,
      a.ACCT_TYPE,
      (SELECT COUNT (
      DISTINCT TO_CHAR (day_date, 'mm')
      FROM PIO_TIMES
      WHERE day_date BETWEEN a.day_date
      AND NVL ( T.MAT_DATE,A.DAY_DATE) 
      AND TO_CHAR (day_date, 'dd') = '31') Test
    Here how can I build the logic for inside select statement.
    I tried to build the separate stream for the inside select statement but I am confusing how to handle the count in the inside the query.
    Please help me how to build the logic for the inside query statement .
    Thanks & Regards,
    Ramana.

    Hi Balakrishna,
    Thanks for your support
    I have applied but I am not getting the column in the output columns from the custom sql function.
    As per the procedure we are using the all conditions like between and month or date conditions  to find the count of distinct months.
    If we use partial conditional in the custom SQL  and partial conditionals in the lookup condition clause is it give the same result?
    How can we get the field of custom sql in the output field.
    Thanks & Regards,
    Ramana.

  • Queerish behavior of 'IN' sub query

    Hii all,
    I've encountered strange behavior of in clause.Here I'm providing a test case.
    SQL> Create table r_dummy_1
      2  as select object_name from user_objects
      3  where rownum <= 10
      4  ;
    Table created.
    SQL> select object_name from r_dummy_1;
    OBJECT_NAME
    CP_ST_CRITERIA
    CP_ST_EXPENSE_CODE
    CP_ST_FACILITIES
    CP_ST_FACILITY_INFO
    CP_ST_FAC_RESULT
    CP_ST_INSTR_RESULT
    CP_ST_RATINGS
    CP_ST_RESULT_SET_DATE
    CP_ST_RLTNSP_NAME
    CP_ST_SIC_CODES
    10 rows selected.I don't have a column named 'NAME' in my table 'R_DUMMY_1'.
    But....
    select *
    from user_source
    where name in(
                           select name
                           from r_dummy_1
                 )This query runs fine !!!!!!!!!!!!!!!
    And when I individually run the inner query
    SQL>  select name
      2                         from r_dummy_1;
    select name
    ERROR at line 1:
    ORA-00904: "NAME": invalid identifierIs this is a bug??

    Hi,
    RGH wrote:
    I thought the inner query executes first(Unlike correlated sub queries) and the outer picks the name matching in the result set.The optimizer decides whether the sub-query gets executed first or not.
    Consider this query:
    SELECT  *
    FROM    scott.emp
    WHERE   1 = 2
    AND     deptno  IN (SELECT ...)
    ;The sub-query may not be run at all, because the optimizer "short-circuits". That is, it sees that the WHERE clause will resolve to FALSE regardless of what the sub-query produces, so it won't waste time running the sub-query.
    Most of the time, assuming the sub-query is run, the results are as if the siub-query gets executed first, but in a correlated sub-query, at least part of the parent query has to be done earlier, because the values referenced in the sub-query have to be fetched before the sub-query can complete.
    So in your query
    select *
    from user_source
    where name in(
                           select name
                           from r_dummy_1
                 )The main query has to decide whether or not to include a row (let's say it's a row where name='PROC_X') from user_source, so it runs the sub-query. The sub-query runs, and produces a result set that includes the name from the main query, 'PROC_X'; control returns to the main query, and it compares the name to the results of the sub-query. The net effect is the same as:
    select *
    from user_source
    where name in(name)For all I know, the optimizer may realize this, and re-write the query to actually perform the second version, never touchiung r_dummy_1 at all.

  • Urgent - Cannot run sub query from VB 6

    Hello!
    I'm having a problem with my Oracle OLE DB connection in windows using Visual Basic 6.0 SP3.
    I can run normal queries just fine, but a correlated sub query like this:
    select A.col_a, (select col_b from Tab_B where id = A.id) from Tab_A A
    returns the following error:
    "ORA-00907: missing right parenthesis"
    But I'm able to run the query witout errors in Toad with the correct result!
    So basically, I cannot run a (correlated?) sub query via OLE DB...
    What am I doing wrong?? Is it a parameter that I need to set on the connection of command?
    I'm not using stored procedures, only plain text SQL.
    Very thankful for a quick answer, this is really urgent. If you have the possibility, please e-mail me at:
    [email protected]
    Thank you in advance.
    Best regards,
    Bnar Baban

    Hi!
    I'm running the latest version of Oracle OLE DB...when checking more in detail, it seems that the provider parses the code in a way, that makes the "(select" part of the sub statement be interpreted as a column name....when it does not find a right parenthesis, but a white space, it complains.
    I switched to Microsoft MSDAORA provider, and now it works perfectly...
    /Bnar

  • Need to include duplicate records in sub query

    Hi All,
             I am using the following query and i am getting error message that your sub query return dupliate records and throwing error. Actually i need these duplicate records for my report. I want to get records for
    whole year like
       JAN FEB MARCH ..   ...    ...
    and idea how i can achieve this task and my query is as follows
     select pmnum
     ,SITEID,
     (select description from locations where pm.location = locations.location and pm.siteid=locations.siteid) as site,
     (select description from commodities where commodities.commodity=  pm.commoditygroup) as workcategory,
     description, (select wonum from workorder where workorder.pmnum = pm.pmnum
     and  targstartdate < '2013-02-01') as jan,
     (select wonum from workorder where workorder.pmnum = pm.pmnum and
     workorder.status<>'CAN' and targstartdate >= '2013-02-01' and
     targstartdate < '2013-03-01') as feb,
     (select wonum from workorder where workorder.pmnum = pm.pmnum and
     workorder.status<>'CAN' and targstartdate >= '2013-03-01' and
     targstartdate < '2013-04-01') as mar
    (select name from companies where companies.company = pm.vendor) as contractor 
           from pm  where ((PM.siteid = 'AAA'))

    Subqueries in the SELECT column list must return a scalar value (single row, single column).  If you need multiple rows returned, use a join instead.  But you need to consider what will happen when more than one row is returned by more than one
    of the joins because these are correlated with the pm table row but not each other.  For example, let's say you have a single row returned from "pm" matching 5 sites and 3 workcategories.  This will result in 15 rows being returned for the single
    pm row.
    Below is an untested example.
    SELECT
    pmnum
    ,SITEID
    ,locations.description as site
    ,commodities.description as workcategory
    ,pm.description
    ,workorder_jan.wonum AS jan
    ,workorder_feb.wonum AS feb
    ,workorder_mar.wonum AS mar
    ,companies.name AS contractor
    FROM dbo.pm
    LEFT JOIN dbo.locations ON pm.location = locations.location
    AND pm.siteid=locations.siteid
    LEFT JOIN dbo.commodities ON commodities.commodity = pm.commoditygroup
    LEFT JOIN dbo.workorder AS workorder_jan ON workorder_jan.pmnum = pm.pmnum
    AND workorder_jan.targstartdate < '2013-02-01'
    LEFT JOIN dbo.workorder AS workorder_feb ON workorder_feb.pmnum = pm.pmnum
    AND workorder_feb.status <> 'CAN'
    AND workorder_feb.targstartdate >= '2013-02-01'
    AND workorder_feb.targstartdate < '2013-03-01'
    LEFT JOIN dbo.workorder AS workorder_mar ON workorder_mar.pmnum = pm.pmnum
    AND workorder_mar.status <> 'CAN'
    AND workorder_mar.targstartdate >= '2013-03-01'
    AND workorder_mar.targstartdate < '2013-04-01'
    LEFT JOIN dbo.companies ON companies.company = pm.vendor
    WHERE pm.siteid = 'AAA';
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • ALL Clause with correlated sub queries

    I have two Tables. emp and dep. In Employee emp_id and Name where emp_id is pk. emp_id is referencing emp_id in Department where Dep has 3 columns emp_id Dep_no and Dep_name. In Department table emp_id is PK.
    Say: Employee Has these data: 1|john and 2|Elen and 3|Ron AND Department Table Has 1|10|Accounts and 2|20|IT.
    I give the following Query:
    SELECT * from Employee E where emp_id = ALL (select emp_id from Department D where D.emp_id = E.emp_id);
    I suppose i should get 1|john . But Im getting All rows of Employee. Why is that D.emp_id = E.emp_id has no effect. Cant seem to understand the query plan too

    Hi,
    ramki_noubang wrote:
    im using oracle 10G XE.
    consider two tables manager_emp and emp_rk: see the results below.
    select * from manager_emp;
    EMP_ID     LAST_NAME MANAGER_ID
    1     ram     3
    2     raj     3
    3     govi     100
    100     mgr     -Once again, post CREATE TABLE and INSERT statements for the sample data.
    select * from emp_rk;
    ID     NAME     DPNO     SAL
    1     ram     10     1000
    2     jon     10     2000
    3     man     10     1500
    4     dan     30     5000
    select * from manager_emp m
    where (emp_id,last_name) *= all* (select id,name from emp_rk e
    where e.id = m.emp_id and e.name = m.last_name);
    EMP_ID     LAST_NAME MANAGER_ID
    1     ram     3
    2     raj     3
    3     govi     100
    100     mgr     -
    i should get only:
    EMP_ID     LAST_NAME MANAGER_ID
    1     ram     3Think about what's happening.
    The main query is just
    SELECT  *
    FROM    manager_emp  m
    WHERE   (emp_id, last_name)   = ALL (subquery)
    ;The subquery is correlated to the main query; that means for each row in manager_emp, the subquery will be run to see if the main WHERE condition is TRUE or not.
    Think about what happens when it's deciding whether or not to include the row
    EMP_ID     LAST_NAME      MANAGER_ID
    2     raj            3It will run this sub-query:
    ...         SELECT  id
             ,         name
             FROM    emp_rk  e
             WHERE   e.id    = 2          -- because m.emp_id = 2
             AND     e.name  = 'raj'     -- because m.last_name = 'raj'The sub-query will find 0 rows, and so the main WHERE condition will be TRUE, because "x = ALL (subquery)" is defined as TRUE when the subquery produces no rows.
    If you want just the 1 row you mentioned, then one way to get it is an uncorrelated sub-query, something like this:
    SELECT  *
    FROM    manager_emp
    WHERE   (emp_id, last_name)   IN
             SELECT  id, name
             FROM    emp_rk
    ;Once again: forget about "= ALL". Everybody else has, and there's a good reason.

  • 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

  • Can someone please help me with a sub query question?

    I need to list a 3rd party contract and then a list of students who belong to that contract.
    On the students segment of the listing I need to show students with student id, name, total credit hours,
    total amount spent on tuition, total amount spent on books and total amount spent on misc.
    This code has a query for the contract information and I get that just fine.
    Then it has a query that gives me total credit hours and that works fine
    then it has a query that gives me total amount spent on tuition and that works fine
    but
    when I add the next query to get total amount spent on books I get only the information for the contract, I don't get student stuff anymore.
    I would really appreciate any guidance that you could give.
    Thanks in advance, Bob Hohulski
    DECLARE
    l_conn utl_TCP.connection;
    v_filehandle utl_file.file_type;
    v_output varchar2(1000);
    v_contract_id varchar2(9);
    v_contract_addr1 varchar2(30);
    v_contract_addr2 varchar2(30);
    v_contract_city varchar2(20);
    v_contract_stat varchar2(03);
    v_contract_zip varchar2(10);
    v_contract_name varchar2(60);
    v_student_id varchar2(09);
    v_student_first_name varchar2(15);
    v_student_mid_name varchar2(15);
    v_student_last_name varchar2(60);
    v_last_out varchar2(20);
    v_student_detail_code varchar2(04);
    v_student_amount number(12,2);
    v_student_ref_number varchar2(09);
    v_credit_hrs number(7,2);
    v_tuition_amount number(12,2);
    v_books_amount number(12,2);
    v_misc_amount number(12,2);
    v_total_for_student number(12,2);
    v_current_student varchar2(09);
    v_sftregs_pidm varchar2(09);
    v_tbraccd_pidm varchar2(09);
    CURSOR c_sel_contract IS
    SELECT DISTINCT spriden_id, spriden_last_name,
    spraddr_street_line1, spraddr_street_line2,
    spraddr_city, spraddr_stat_code, spraddr_zip
    FROM spriden, spraddr
    -- WHERE spriden_id = '&Enter_Id'
    where spriden_id = 'T10474666'
    AND spriden_pidm = spraddr_pidm
    AND SPRIDEN_CHANGE_IND IS NULL;
    CURSOR c_sel_student IS
    SELECT DISTINCT spriden_id, spriden_first_name, spriden_mi, spriden_last_name,
    sftregs_credit_hr,
    tbraccd_amount,
    sftregs_pidm,
    tbraccd_pidm
    FROM spriden, tbraccd, tbbcstu, sftregs
    WHERE 559220 = tbbcstu_contract_pidm
    AND spriden_pidm = tbraccd_pidm
    AND spriden_pidm = tbbcstu_stu_pidm
    AND spriden_pidm = sftregs_pidm
    AND (sftregs_pidm, sftregs_credit_hr) IN
    (SELECT DISTINCT sftregs_pidm, SUM(sftregs_credit_hr)
    FROM sftregs, tbbcstu, spriden
    WHERE sftregs_term_code = '201010'
    AND sftregs_pidm = tbbcstu_stu_pidm
    AND sftregs_pidm = spriden_pidm
    GROUP BY sftregs_pidm)
    AND (tbraccd_pidm, tbraccd_amount) IN
    (SELECT DISTINCT tbraccd_pidm, SUM(tbraccd_amount)
    -- tuition
    FROM tbraccd, tbbcstu, spriden
    WHERE tbraccd_term_code = '201010'
    AND (tbraccd_detail_code = 'TU01' OR
    tbraccd_detail_code = 'TU02' OR
    tbraccd_detail_code = 'TU03' OR
    tbraccd_detail_code = 'TU04')
    AND tbraccd_pidm = tbbcstu_stu_pidm
    AND tbraccd_pidm = spriden_pidm
    GROUP BY tbraccd_pidm)
    --this code works up to this point
    --when I add the next query I get nothing
    AND (tbraccd_pidm, tbraccd_amount) IN
    (SELECT tbraccd_pidm, SUM(tbraccd_amount)
    books
    FROM tbraccd, tbbcstu
    WHERE tbraccd_term_code = '201010'
    AND (tbraccd_detail_code = 'BKSU' OR
    tbraccd_detail_code = 'BKCH')
    AND tbraccd_pidm = tbbcstu_stu_pidm
    GROUP BY tbraccd_pidm, tbraccd_amount)
    --AND (tbraccd_pidm, tbraccd_amount) IN
    -- (SELECT tbraccd_pidm, SUM(tbraccd_amount)
    -- misc
    -- FROM tbraccd, tbbcstu
    -- WHERE tbraccd_term_code = '201010'
    -- AND tbraccd_pidm = tbbcstu_stu_pidm
    -- AND (tbraccd_detail_code = 'AUNA' OR
    -- tbraccd_detail_code = 'OTPB')
    -- GROUP BY tbraccd_pidm, tbraccd_amount)
    --ORDER BY tbraccd_pidm, spriden_first_name, spriden_mi, spriden_last_name,
    -- tbbcstu_sponsor_ref_number, sftregs_credit_hr;
    ORDER BY tbraccd_pidm;
    BEGIN
    v_filehandle := utl_file.fopen(location => 'UTLFILE_MISAP9',
    filename => 'ban_matrix.dat',
    open_mode => 'w',
    max_linesize => 32767);
    OPEN c_sel_contract;
    LOOP
    DBMS_OUTPUT.PUT_LINE('looping');
    FETCH c_sel_contract INTO v_contract_id, v_contract_name,
    v_contract_addr1, v_contract_addr2,
    v_contract_city, v_contract_stat,
    v_contract_zip;
    EXIT WHEN c_sel_contract%NOTFOUND;
    v_output :=
    nvl(rpad(v_contract_id,9),rpad(' ',9)) ||
    ' ' ||
    nvl(rpad(v_contract_name,60),rpad(' ',60));
    utl_file.put_line(v_filehandle,v_output);
    v_output :=
    nvl(rpad(v_contract_addr1, 30),rpad(' ',30)) ||
    ' ' ||
    nvl(rpad(v_contract_addr2, 30),rpad(' ',30));
    utl_file.put_line(v_filehandle,v_output);
    v_output :=
    nvl(rpad(v_contract_city, 20), rpad(' ',20)) ||
    ' ' ||
    nvl(rpad(v_contract_stat, 3), rpad(' ',3)) ||
    ' ' ||
    nvl(rpad(v_contract_zip, 10), rpad(' ',10));
    utl_file.put_line(v_filehandle,v_output);
    utl_file.new_line(v_filehandle);
    OPEN c_sel_student;
    LOOP
    FETCH c_sel_student into v_student_id, v_student_first_name, v_student_mid_name,
    v_student_last_name,
    v_credit_hrs,
    v_tuition_amount,
    v_sftregs_pidm,
    v_tbraccd_pidm;
    -- v_books_amount, v_misc_amount;
    EXIT WHEN c_sel_student%NOTFOUND;
    v_last_out := substr(v_student_last_name, 1, 20);
    v_output :=
    nvl(rpad(v_student_id, 09),rpad(' ',09)) ||
    ' ' ||
    nvl(rpad(v_student_first_name, 15),rpad(' ',15)) ||
    nvl(rpad(v_student_mid_name, 15),rpad(' ',15)) ||
    nvl(rpad(v_last_out, 20),rpad(' ',20)) ||
    ' ' ||
    nvl(rpad(v_student_ref_number, 09),rpad(' ',09)) ||
    ' ' ||
    v_credit_hrs ||
    ' ' ||
    v_tuition_amount ||
    -- v_books_amount ||
    -- ' ' ||
    -- v_misc_amount;
    utl_file.put_line(v_filehandle,v_output);
    END LOOP;
    END LOOP;
    --EXCEPTION
    --WHEN OTHERS THEN
    -- DECLARE
    -- err_msg VARCHAR2(100);
    -- BEGIN
    -- err_msg := 'ERR- '||SUBSTR(SQLERRM, 1,100);
    -- - utl_file.put_line(v_filehandle,err_msg);
    --END;
    utl_file.fclose(v_filehandle);
    CLOSE c_sel_contract;
    CLOSE c_sel_student;
    --END AR_MATRIX_PROC;
    END;

    run this original query
    SELECT DISTINCT spriden_id,
            spriden_first_name,
            spriden_mi,
            spriden_last_name,
            sftregs_credit_hr,
            tbraccd_amount,
            sftregs_pidm,
            tbraccd_pidm
       FROM spriden, tbraccd, tbbcstu, sftregs
    WHERE 559220 = tbbcstu_contract_pidm
       AND spriden_pidm = tbraccd_pidm
       AND spriden_pidm = tbbcstu_stu_pidm
       AND spriden_pidm = sftregs_pidm
       AND (sftregs_pidm, sftregs_credit_hr) IN (SELECT DISTINCT sftregs_pidm, SUM(sftregs_credit_hr)
                                                   FROM sftregs, tbbcstu, spriden
                                                  WHERE sftregs_term_code = '201010'
                                                    AND sftregs_pidm = tbbcstu_stu_pidm
                                                    AND sftregs_pidm = spriden_pidm
                                                 GROUP BY sftregs_pidm)
       AND (tbraccd_pidm, tbraccd_amount) IN (SELECT DISTINCT tbraccd_pidm, SUM(tbraccd_amount)
                                              -- tuition
                                                FROM tbraccd, tbbcstu, spriden
                                               WHERE tbraccd_term_code = '201010'
                                                 AND (tbraccd_detail_code = 'TU01' OR
                                                      tbraccd_detail_code = 'TU02' OR
                                                      tbraccd_detail_code = 'TU03' OR
                                                      tbraccd_detail_code = 'TU04')
                                                 AND tbraccd_pidm = tbbcstu_stu_pidm
                                                 AND tbraccd_pidm = spriden_pidm
                                               GROUP BY tbraccd_pidm)
       AND (tbraccd_pidm, tbraccd_amount) IN (SELECT tbraccd_pidm, SUM(tbraccd_amount) books
                                                FROM tbraccd, tbbcstu
                                               WHERE tbraccd_term_code = '201010'
                                                 AND (tbraccd_detail_code = 'BKSU' OR
                                                      tbraccd_detail_code = 'BKCH')
                                                 AND tbraccd_pidm = tbbcstu_stu_pidm
                                              GROUP BY tbraccd_pidm, tbraccd_amount)
    ORDER BY tbraccd_pidm;then run this sub-query:
    SELECT tbraccd_pidm, SUM(tbraccd_amount) books
       FROM tbraccd, tbbcstu
      WHERE tbraccd_term_code = '201010'
        AND (tbraccd_detail_code = 'BKSU' OR
             tbraccd_detail_code = 'BKCH')
       AND tbraccd_pidm = tbbcstu_stu_pidm
    GROUP BY tbraccd_pidm, tbraccd_amount)see if you have a matching tbraccd_pidm and tbraccd_amount between the two results.

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

    833560 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!

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

    You 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

  • How to use SQL Query in OBIEE Reports

    Hi all,
    I need to use direct sql query in report function column.. How can I implement that.
    For example
    Our report name is /shared/Automotive/Vehicle Services/Most Serviced Vehicle Models
    we have to eliminate /shared/Automotive/Vehicle Services/ part from above report name.. I have done this in sql using the Query SUBSTR(COL,INSTR(COL,'/',1,4)+1).
    So kindly help how to implement above sql query in Obiee.. Urgent.
    Thanx in advance

    796797 wrote:
    Hi all,
    I need to use direct sql query in report function column.. How can I implement that.
    For example
    Our report name is /shared/Automotive/Vehicle Services/Most Serviced Vehicle Models
    we have to eliminate /shared/Automotive/Vehicle Services/ part from above report name.. I have done this in sql using the Query SUBSTR(COL,INSTR(COL,'/',1,4)+1).
    So kindly help how to implement above sql query in Obiee.. Urgent.
    Thanx in advanceArrggh. I wish people wouldn't just answer a question without taking the time to actually think about what the user is asking for and if it makes sense. I like Diney's response best: Why not use the Title View? (i.e., asking questions until it is clear what is needed.) So along those lines, why are you trying to put the name of your report in a column of your report?? And why do you need to use direct sql to do this??
    Kindly or not, urgent or not, state what you are trying to achieve and why you need it (if the obvious answer like "using the Title View" doesn't work for you), instead of simply assuming your method is right and you need to know how to do what envision. Your method may not be correct or necessary.

Maybe you are looking for

  • Has anyone tried changing the drummer on a drummer part that has already been placed into a track stack?

    Has anyone tried changing the drummer on a drummer part that has already been placed into a track stack? I find that if I do that, the parts in the stack all get merged together with no way to expand them (ie the triangle you would click on to expand

  • How can I make a "glowing" effect?

    This seems a bit ridiculous. I work with premiere all the time, and I know I've seen this a million times before, but I have no idea how to create it. I have a beauty shot of a product and I want the footage to "glow", I used to do it all the time fo

  • Cannot compile program

    Hi all, I?m unable to compile the following code. Does anybody know what I did wrong? In the main method the program asks for 3 values which then are used in the auto-class to do a calculation. But I made some mistake within the constructor and I don

  • Can't import CD's with windows vista

    I seem to be having the issue with windows media player to so i don't think it's an issue with Itunes but maybe someone can offer some advice on settings I am using a plextor px810-sa on my over pc and when i put a cd in itunes see's it, then when i

  • 8.1 update stuck iPhone 6 Plus

    Updated to 8.1 earlier on my 6+ didn't go well:  phone was running hot, documents weren't synching, handoff didn't seem to be working right.  No worries, I'll just do a DFU restore. Started the restore and it's stuck.  No movement in the progress bar