Using outter joins

need to create a report based on three tables: emp,dept, and loc. There dept can have null dept and loc and the user wants to see these records; therefore, we need to do an outter join. Also, the user wants to have bind variables so he/she can put any of these variables (dept or loc) and based on that return the records.
select emp.name, dept.name, loc.name
from emp, dept, loc
where dept.deptno = emp.deptno(+)
and loc.locid = emp.loc(+)
and dept.deptno = :department
and loc.locid = :location
I need to find and join those records that are null. I took the following approach, but I'm not sure if this is correct:
1. created a table based on emp and converted those null dept and loc w/ -1
2. joined the tables
3. do the query based on the table
4. the bind variable will have a like so that if the user doesn't insert a field I will have the wild card (%) so it will bring all records
select emp.name, dept.name, loc.name
from emp, dept, loc, (select nvl(deptno, -1) as deptno, nvl(loc, -1) as loc from emp) temp
where dept.deptno = emp.deptno(+)
and loc.locid = emp.loc(+)
and temp.deptno = nvl(dept.deptno, -1)
and temp.loc = nvl(loc.id, -1)
and temp.deptno like nvl(:department, '%')
and temp.locid like nvl(:location, '%')
I think that I'm overdoing this query though. Let me know!
;-P
Marcelo

Hi, since oracle 9i it is possible to use the ansi join syntax in Oracle sql.
You can use a "full out join", "left outer join", "right outer join"
Example return all rows with NULLs from all tables:
select e.last_name, d.department_name, d.department_id, j.job_title, l.city
from employees e
     full outer join departments d on (e.department_id=d.department_id )
     full outer join jobs j on (e.job_id=j.job_id)
     full outer join locations l on (l.location_id=d.location_id)
see docu: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2107297
Lutz

Similar Messages

  • Issue found with Oracle 11.2.0.2 left outter joins.

    When performing a left outter join, that returns no data - we are seeing an issue with 11.2.0.2 where it does not return any rows at all - where it should in fact return one row with null data. We have thoroughly tested this against 11.2.0.1 as well as 10g and found no issues, but for some reason 11.2.0.2 does not perform as expected.
    The following queries demonstrate what we're experiencing, and the subsequent DDL / DML will expose this issue on a 11.2.0.2 oracle DB.
    -- QUERIES --
    --Query that exposes the LOJ issue (should return one row with 4 null columns)
    -- RETURNS: NO ROWS ARE RETURNED
    SELECT lt.*
    FROM Attr attr
    JOIN Obj obj ON attr.id = obj.id
    LEFT OUTER JOIN Loc_Txt lt ON attr.id = lt.objectid AND lt.typeid = 851 AND 1 = 2
    WHERE attr.id = 225;
    --PLEASE NOTE, the 'AND 1 = 2' is necessary for our particular use case.  While this doesn't make much logical sense here, it is necessary to expose this issue.
    --Query - shows the expected behavior by simply adding a column that is not null.
    --RETURNS: ONE ROW RETURNED with first 4 columns null, and '225' for obj.id.
    SELECT lt.*, obj.id
    FROM Attr attr
    JOIN Obj obj ON attr.id = obj.id
    LEFT OUTER JOIN Loc_Txt lt ON attr.id = lt.objectid AND lt.typeid = 851 AND 1 = 2
    WHERE attr.id = 225;
    --Query - shows that the expected behavior also resumes by swapping the LoJ against obj.id instead of attr.id.  Since these tables are joined together by id, this should be ARBITRARY!
    -- RETURNS: ONE ROW RETURNED with first 4 columns null, and '225' for obj.id
    SELECT lt.*
    FROM Attr attr
    JOIN Obj obj ON attr.id = obj.id
    LEFT OUTER JOIN Loc_Txt lt ON obj.id = lt.objectid AND lt.typeid = 851 AND 1 = 2
    WHERE attr.id = 225;
    -- DDL --
    -- OBJ TABLE --
    CREATE TABLE "TESTDB"."OBJ"
         "ID" NUMBER(10,0) NOT NULL ENABLE
         ,"TYPEID" NUMBER(10,0) NOT NULL ENABLE
         ,CONSTRAINT "OBJ_PK" PRIMARY KEY ("ID") RELY ENABLE
    commit;
    -- LOC_TXT TABLE --
    CREATE TABLE "TESTDB"."LOC_TXT"
         "ID" NUMBER(10,0) NOT NULL ENABLE,
         "OBJECTID" NUMBER(10,0) NOT NULL ENABLE,
    "TYPEID" NUMBER(10,0) NOT NULL ENABLE,
         "VALUE" NVARCHAR2(400) NOT NULL ENABLE,
         CONSTRAINT "LOC_TXT_PK" PRIMARY KEY ("ID") RELY ENABLE,
         CONSTRAINT "LOC_TXT1_FK" FOREIGN KEY ("OBJECTID") REFERENCES "TESTDB"."OBJ" ("ID") RELY ENABLE
    commit;
    -- ATTR TABLE --
    CREATE TABLE "TESTDB"."ATTR"
         "ID" NUMBER(10,0) NOT NULL ENABLE,
         "ATTRIBUTEVALUE" NVARCHAR2(255),
         CONSTRAINT "ATTR_PK" PRIMARY KEY ("ID") RELY ENABLE,
         CONSTRAINT "ATTR_FK" FOREIGN KEY ("ID") REFERENCES "TESTDB"."OBJ" ("ID") RELY ENABLE
    commit;
    -- DATA --
    insert into obj (id, typeid) values(225, 174);
    insert into attr (id, attributevalue) values(225, 'abc');
    insert into obj (id, typeid) values(2274, 846);
    insert into loc_txt(id, objectid, typeid, value) values(540, 2274, 851, 'Core Type');
    commit;
    -- DROP TABLES --
    --DROP TABLE "TESTDB"."ATTR";
    --DROP TABLE "TESTDB"."LOC_TXT";
    --DROP TABLE "TESTDB"."OBJ";
    --commit;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Whilst I agree that your test cases do show some anomalies, the statement logic does smell a little odd.
    In general, I'd be wary of trying to reproduce issues using hardcoded conditions such as "AND 1=2".
    As this predicate can be evaluated at parse time, you can get plans which are not representative of run time issues.
    However....
    The trouble with ANSI - trouble as in it seems to have a lot of bugs/issues - is that it is always transformed to orthodox Oracle syntax prior to execution - you can see this in a 10053 trace file. This is possibly not helped by the distinction ANSI has between join predicates and filter predicates - something that Oracle syntax does not really have without rewriting the SQL significantly.
    For more information on a similar sounding ANSI problem, see http://jonathanlewis.wordpress.com/2011/08/03/trouble-shooting-4/
    Yours might not even be ANSI related.
    If you check the execution plan - particularly the predicates section, then you can see some of the issues/symptoms.
    See the "NULL IS NOT NULL" FILTER operation at Id 1.
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    SQL> SELECT lt.*
      2  FROM Attr attr
      3  JOIN Obj obj ON attr.id = obj.id
      4  LEFT OUTER JOIN Loc_Txt lt ON attr.id = lt.objectid AND lt.typeid = 851 AND 1 = 2
      5  WHERE attr.id = 225;
    no rows selected
    SQL> explain plan for
      2  SELECT lt.*
      3  FROM Attr attr
      4  JOIN Obj obj ON attr.id = obj.id
      5  LEFT OUTER JOIN Loc_Txt lt ON attr.id = lt.objectid AND lt.typeid = 851 AND 1 = 2
      6  WHERE attr.id = 225;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1392151118
    | Id  | Operation            | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |         |     1 |   454 |     0   (0)|          |
    |*  1 |  FILTER              |         |       |       |            |          |
    |   2 |   NESTED LOOPS OUTER |         |     1 |   454 |     4   (0)| 00:00:01 |
    |*  3 |    INDEX UNIQUE SCAN | ATTR_PK |     1 |    13 |     1   (0)| 00:00:01 |
    |   4 |    VIEW              |         |     1 |   441 |     3   (0)| 00:00:01 |
    |*  5 |     TABLE ACCESS FULL| LOC_TXT |     1 |   441 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter(NULL IS NOT NULL)
       3 - access("ATTR"."ID"=225)
       5 - filter("ATTR"."ID"="LT"."OBJECTID" AND "LT"."TYPEID"=851)
    Note
       - dynamic sampling used for this statement (level=4)
    23 rows selected.
    SQL> Whereas in the next example, the FILTER operation has moved further down.
    SQL> SELECT lt.*, obj.id
      2  FROM Attr attr
      3  JOIN Obj obj ON attr.id = obj.id
      4  LEFT OUTER JOIN Loc_Txt lt ON attr.id = lt.objectid AND lt.typeid = 851 AND 1 = 2
      5  WHERE attr.id = 225;
            ID   OBJECTID     TYPEID
    VALUE
            ID
           225
    1 row selected.
    SQL> explain plan for
      2  SELECT lt.*, obj.id
      3  FROM Attr attr
      4  JOIN Obj obj ON attr.id = obj.id
      5  LEFT OUTER JOIN Loc_Txt lt ON attr.id = lt.objectid AND lt.typeid = 851 AND 1 = 2
      6  WHERE attr.id = 225;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2816285829
    | Id  | Operation            | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |         |     1 |   454 |     1   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS OUTER  |         |     1 |   454 |     1   (0)| 00:00:01 |
    |*  2 |   INDEX UNIQUE SCAN  | ATTR_PK |     1 |    13 |     1   (0)| 00:00:01 |
    |   3 |   VIEW               |         |     1 |   441 |            |          |
    |*  4 |    FILTER            |         |       |       |            |          |
    |*  5 |     TABLE ACCESS FULL| LOC_TXT |     1 |   441 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("ATTR"."ID"=225)
       4 - filter(NULL IS NOT NULL)
       5 - filter("ATTR"."ID"="LT"."OBJECTID" AND "LT"."TYPEID"=851)
    Note
       - dynamic sampling used for this statement (level=4)
    23 rows selected.
    SQL> However, you might have also noticed that OBJ is not referenced at all in the execution plans - this may indicate where the issue lies, maybe in conjunction with ANSI or it may be nothing to do with ANSI.
    The foreign key constraint means that any reference to OBJ can be rewritten and eliminated.
    So, if we remove the foreign key constraint, we get the expected one row with all null values returned:
    SQL> alter table attr drop constraint attr_fk;
    Table altered.
    SQL> SELECT lt.*
      2  FROM Attr attr
      3  JOIN Obj obj ON attr.id = obj.id
      4  LEFT OUTER JOIN Loc_Txt lt ON attr.id = lt.objectid AND lt.typeid = 851 AND 1 = 2
      5  WHERE attr.id = 225;
            ID   OBJECTID     TYPEID
    VALUE
    1 row selected.
    SQL> explain plan for
      2  SELECT lt.*
      3  FROM Attr attr
      4  JOIN Obj obj ON attr.id = obj.id
      5  LEFT OUTER JOIN Loc_Txt lt ON attr.id = lt.objectid AND lt.typeid = 851 AND 1 = 2
      6  WHERE attr.id = 225;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1136995246
    | Id  | Operation            | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |         |     1 |   467 |     1   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS OUTER  |         |     1 |   467 |     1   (0)| 00:00:01 |
    |   2 |   NESTED LOOPS       |         |     1 |    26 |     1   (0)| 00:00:01 |
    |*  3 |    INDEX UNIQUE SCAN | OBJ_PK  |     1 |    13 |     1   (0)| 00:00:01 |
    |*  4 |    INDEX UNIQUE SCAN | ATTR_PK |     1 |    13 |     0   (0)| 00:00:01 |
    |   5 |   VIEW               |         |     1 |   441 |            |          |
    |*  6 |    FILTER            |         |       |       |            |          |
    |*  7 |     TABLE ACCESS FULL| LOC_TXT |     1 |   441 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - access("OBJ"."ID"=225)
       4 - access("ATTR"."ID"=225)
       6 - filter(NULL IS NOT NULL)
       7 - filter("ATTR"."ID"="LT"."OBJECTID" AND "LT"."TYPEID"=851)
    Note
       - dynamic sampling used for this statement (level=4)
    26 rows selected.Note also that with the constraint in place, I did not get a row returned regardless of whether the outer join was to attr.id or obj.id
    Edited by: Dom Brooks on Aug 15, 2011 11:41 AM

  • Full Outter Join

    I have the following PL/SQL that insert into the table ag_comm_statement from 3 data sets, a, b and c. May anybody know how to make a full outter joins for data set a and c (See the section in bold below)? Many thanks in advance.
    insert into ag_comm_statement
    ( month_key
    ,commission_no
    ,comm_cutoff_date
    ,branch_code
    ,branch_name
    -- DW001 Old Start
    -- ,product_category
    -- DW001 Old End
    -- DW001 New Start
    -- ,product_desc
    -- DW001 New End
    ,product_name
    ,payment_mode
    ,fy_no_of_policy
    ,fy_annualised_premium
    ,fy_commission_premium
    ,fy_commission
    ,renew_no_of_policy
    ,renew_commission_premium
    ,renew_commission
    select v_month_key
    ,v_commission_no
    ,v_comm_cutoff_date
    ,a.branch_code
    ,a.branch_name
    -- DW001 Old Start
    -- ,decode(a.product_code,'0107000000','GRIP','0640000000','MISO') product_category
    -- DW001 Old End
    -- DW001 New Start
    -- ,pd.category_desc product_category
    -- ,pd.plan_code_desc product_desc
    -- DW001 New End
    ,b.basic_plan_code product_name
    ,decode(b.payment_mthd,'S','S',lpad(b.payment_mode,2,'0')) payment_mode
    ,count(distinct a.policy_no) fy_no_of_policy
    ,sum(b.afyp) fy_annualised_premium
    ,sum(a.premium) fy_commission_premium
    ,sum(a.fy_commission) fy_commission
    ,count(distinct c.policy_no) renew_no_of_policy
    ,sum(c.premium) renew_commission_premium
    ,sum(c.fy_commission) renew_commission
    from (select a.policy_no
    ,a.product_code
    ,b.branch_code
    ,b.branch_name
    ,sum(round((a.comm_orig_curr * c.spot_rate),2)) fy_commission
    ,sum(a.premium * c.spot_rate) premium
    -- DW001 New Start
    -- ,a.plan_code
    -- DW001 New End
    from dwh.ag_comm_work a
    ,dwh.agent_details@dhkp b
    ,dwh.ag_comm_exchange_rate c
    where a.branch_code = '82610'
    and a.run_date between v_prev_cutoff_date + 1
    and v_comm_cutoff_date
    and a.ptype in ('01','02','03','04','05','11','20')
    and a.reason_code in ('112','114','115')
    and a.agent_code = b.agent_code
    and a.currency = c.ais_code (+)
    and c.run_date = v_comm_cutoff_date
    group by
    a.policy_no
    ,a.product_code
    ,b.branch_code
    ,b.branch_name
    -- DW001 New Start
    -- ,a.plan_code
    -- DW001 New End
    ) a
    ,bis_weekly_data@chkp b
    -- DW001 New Start
    -- ,dwh.product_dim pd
    -- DW001 New End
    ,(select a.policy_no
    ,a.product_code
    ,b.branch_code
    ,b.branch_name
    ,sum(round((a.comm_orig_curr * c.spot_rate),2)) fy_commission
    ,sum(a.premium * c.spot_rate) premium
    from dwh.ag_comm_work a
    ,dwh.agent_details@dhkp b
    ,dwh.ag_comm_exchange_rate c
    where a.branch_code = '82610'
    and a.run_date between v_prev_cutoff_date + 1
    and v_comm_cutoff_date
    and a.ptype in ('01','02','03','04','05','11','20')
    and a.reason_code in ('131','132')
    and a.agent_code = b.agent_code
    and a.currency = c.ais_code (+)
    and c.run_date = v_comm_cutoff_date
    group by
    a.policy_no
    ,a.product_code
    ,b.branch_code
    ,b.branch_name
    ) c
    where a.policy_no = substr(b.contract_no (+),3, 7)
    and c.policy_no (+) = a.policy_no
    and c.branch_code (+) = a.branch_code
    and c.product_code (+) = a.product_code
    -- DW001 New Start
    -- and pd.plan_code = a.plan_code
    -- and pd.coverage_indicator = 'BASIC'
    -- and pd.level_col = 'DETAIL'
    -- DW001 New End
    group by
    a.branch_code
    ,a.branch_name
    ,a.product_code
    ,b.basic_plan_code
    ,b.payment_mode
    ,b.payment_mthd
    -- DW001 New Start
    -- ,pd.category_desc
    -- ,pd.plan_code_desc
    -- DW001 New End
    exception
    when others then
    dbms_output.put_line('insert data error!');
    rollback;
    raise;

    Hi psiplaw
    First of all yours query is too complex to understand ,why dont you create view for table c and then use full outer join??
    select e.empno,e.ename,d.deptno,d.dname,l.locid
    from emp e
    full outer join dept d on (e.deptno=d.deptno)
    full outer join location l on (d.locid=l.locid);
    any how have a look there
    http://asktom.oracle.com/pls/ask/f?p=4950:8:1563052620953158875::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:7350850093871
    Message was edited by:
    pcbyte12
    Message was edited by:
    pcbyte12

  • Need help to join two tables using three joins, one of which is a (between) date range.

    I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
    the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
    ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
    [ABCTABLE]
    ABCORDER
    ABCPART
    ABCSERIAL
    ABCDATE
    [ZYXTABLE]
    XYZORDER
    XYZPART
    XYZSERIAL
    XYZDATE1
    XYZDATE2

    Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
    on this computer. There are no "Null" fields in either of the tables. 
    This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
    [MSORDR]
    MSORDER
    MSPART
    MSSERIAL
    MSOPNDATE
    11111111
    4444444
    55555
    2/4/2015
    22222222
    6666666
    11111
    1/6/2015
    33333333
    6666666
    11111
    3/5/2015
    This table has one order for every part number and every serial number.
    [GLORDR]
    GLORDER
    GLPART
    GLSERIAL
    GLSTARTDATE
    GLENDDATE
    ABC11111
    444444
    55555
    1/2/2015
    4/4/2015
    ABC22222
    666666
    11111
    1/5/2015
    4/10/2015
    AAA11111
    555555
    22222
    3/2/2015
    4/10/2015
    Post Query table
    GLORDER
    MSORDER
    GLSTARTDATE
    GLENDDATE
    MSOPNDATE
    ABC11111
    11111111
    1/2/2015
    4/4/2015
    2/4/2015
    ABC22222
    22222222
    1/5/2015
    4/10/2015
    1/6/2015
    ABC22222
    33333333
    1/5/2015
    4/10/2015
    3/5/2015
    This is the SQL minus the between date join.
    SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
    FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART);

  • Order Query in SQ01 using Table Joins in CRM

    Hello Experts,
    I am trying to create a query using table joins in SQ01 in CRM because I need a report that will give me all transactions for a selected Business Partner.  I am unable to display any results when running my query.  I have found other threads which give a list of possible tables to join together, but the fields used in the joins were not described. 
    The tables I have joined in my query are as follows:
    CRMD_ORDERADM_H
    CRMD_ORDER_INDEX
    CRMD_PARTNER
    BUT_000
    I have used SE16 to try to search for additional tables to use for linking the Business Partner with a transaction, but I have been unsuccessful.
    Would anyone please give advice as how to proceed? 
    Reward points are available!
    Thank you in advance,
    David

    David
    The link with be the GUID.
    CRMD_ORDERADM_H = Document Header Table
    CRMD_ORDERADM_I = Document Line item Table
    CRMD_LINK = Lists various ‘link’ GUIDs, to
    access order Information
    The Table CRMD_ORDERADM_H will contain you transactions , once you find the GUID of your sales transaction in the table CRMD_ORDERADM_H.
    You then need to check the table CRMD_LINK.
    In this table you will then find a number in 11 = sales. This refers to the table CRMD_SALES. There are also links to many other tables ie Shipping, pricing, org etc.
    CRMM_BUT_SET0140 - for Sales Group, Sales Office, District
    CRMM_BUT_LNK0141 - for Sales Area data
    Transaction CRMD_BUS2000115 allows you to see all sales transactions for a BP. CRMD_BUS2000126 shows you activities for selected BP.
    Regards
    M

  • Using nested Joins in abap prog

    Hi All,
    please help me  out in using nested joins in abap progrmaming. I dont know about joins in abap.specially in case of outer join.
      I have 5 internal tables.. mara ,marc, mvke,mbew,ampl. am using  a  select query with certain fields from all these tables.
      I need to disply  all the materials  of  a mara for  a particular date irrespective of  the values in fields of  other tables.
            Even if that materail is not present in other table for certain condtion ,that material  should get displyed with all other fields  showing null value..

    Hi RK,
    the  code am using is of the same way...but my problem was with the joins..in the  select query  am using nested join combining inner  and outer join.. but i could  not able to display all the materials  of mara of a particular date..
    The code looks like this..
    SELECT <some fields.......>
    INTO  TABLE i_materials
          FROM  ( marc AS b
          INNER JOIN mara AS a ON amatnr = bmatnr
          INNER JOIN mvke AS c ON cmatnr = amatnr
          INNER JOIN ampl AS g ON gbmatn = amatnr
          LEFT OUTER JOIN mbew AS d ON dmatnr = bmatnr
                                   AND dbwkey = bwerks )
      WHERE a~matnr  IN s_matnr AND .................
    Else
    SELECT <some fields.......>
    INTO  TABLE i_materials
          FROM  ( marc AS b
          INNER JOIN mara AS a ON amatnr = bmatnr
          INNER JOIN mvke AS c ON cmatnr = amatnr
          INNER JOIN ampl AS g ON gbmatn = amatnr
          LEFT OUTER JOIN mbew AS d ON dmatnr = bmatnr
                                   AND dbwkey = bwerks )
       FOR ALL ENTRIES IN i_mara
         WHERE a~matnr = i_mara-matnr AND ............

  • In which condition Table valued function should prefer over SP except use in joins?

    Hi, 
    My requirements is:
    Entity framework needs to call DB object (TVF or SP), which will provide some data to them and they'll work on it at app level.
    DB object would be simple, one result set, it will join 5 tables and get around 30 columns to them. it would be parameterized query so can't use view.
    Now my question is what DB object would be best to use, table valued function or store procedure. and why?
    I google on it, I find some interesting links (example http://technet.microsoft.com/en-us/library/ms187650(v=sql.105).aspx)
    they mentioned conditions to convert SP to TVF but not mentioned the reason, why I should convert?
    Both have same cache plans strategy. SP has so many advantages over TVF, but I don't see any technical advantage of TVF over SP except it can be use in joins or so. 
    so In short my question is, why I can't use SP in all cases, why I would use TVF?, and which Table valued or multi-valued?
    would appreciate your time and response.

    According to a few recent blogs you should be able to use TVP or stored procedure with EF 6.1.2 with ease. In our application we haven't switched yet to 6.1.2 (we're using 6.0.0) and there is no support for stored procedures or functions so we use StoreQuery.
    I am wondering if you can share your experience of using EF with SP or TVP (and document the steps).
    I am also wondering as how exactly it's working behind the scenes and where the full query is taking place. Say, in our case we may want to add some extra conditions after retrieving a set using, say, SP. Would the final query execute on the client (e.g.
    SP executed on the server, result returned and then extra conditions executed on the "client")?
    As I said, right now we're using StoreQuery which means that our extra conditions must be case - sensitive as opposed to SQL Server case insensitive. So, if someone already tried that scenario and can tell me how exactly it works, I would appreciate it.
    Another question about EF - I defined a property as  
     [Column(TypeName = "varchar")]
            public string PhoneNumber { get; set; } // area code + phone
    and in the LINQ query as 
    var query = db.Accounts.Select(a => new AccountsList
    AcctName = a.AcctName,
    Contact = a.Contact,
    FullName = a.FullName,
    AreaCode = a.AreaCode,
    Phone = a.Phone,
    Hidden = a.Hide,
    Hide = a.Hide,
    PhoneNumber = a.AreaCode.Trim() + a.Phone.Trim(),
    AcctTypeId = a.AcctTypeId
    and I see that it's translated into CASE AreaCode IS NULL THEN N'' ELSE RTRIM(LTRIM(areaCode)) END + ... 
    My question is - why EF does it if there is no mentioning at all in the class as how NULL is supposed to be treated. Is it a bug?
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • How to use outer join condition in my below query.

    Hi All,
    How to use outer join condition in my below query.
    In the table  APPS_JP.GEDIS_OFFER_HEADER goh I have more records
    in the table APPS_JP.GEDIS_ORDER_BUILDS gob I have less number of records.
    I want all the records from APPS_JP.GEDIS_OFFER_HEADER goh
    including other conditions.
    I have tried goh.OFFER_NO=gob.OFFER_NO(+) but same result.
    [code]SELECT   GOH.ORIG_SYSTEM,
               gsp.USER_NAME,
               goh.ORDER_NO,
               goh.OMEGA_ORDER_NUMBER,
               goh.ORDER_TYPE,
               gc.CUSTOMER_ID,
               gc.OMEGA_CUSTOMER_NUMBER,
               CASE WHEN gc.PRIVATE = 'N' THEN gc.CUSTOMER_NAME ELSE '' END
                  AS COMPANY_NAME,
               goh.ORDER_STATUS,
               goh.TOTAL_SELLING_PRICE,
               goh.TOTAL_MARGIN,
                  ga1.ADDRESS1
               || ','
               || ga1.ADDRESS2
               || ','
               || ga1.ADDRESS3
               || ','
               || ga1.POSTAL_CODE
               || ','
               || ga1.CITY
                  AS SHIPPING_ADDRESS,
                  ga2.ADDRESS1
               || ','
               || ga2.ADDRESS2
               || ','
               || ga2.ADDRESS3
               || ','
               || ga2.POSTAL_CODE
               || ','
               || ga2.CITY
                  AS BILLING_ADDRESS,
               ga.ADDRESS_ID,
               gol.DESCRIPTION,
               APPS_JP.TZ.to_local_date (goh.OFFER_DATE, goh.OFFER_DATE_UTC)
                  AS OFFER_DATE,
               gc.LEVEL_8,
               goh.NO_OF_BUILDS,
               gob.SFDC_ID,
               goh.PURCHASE_ORDER_NO AS PO,
               gc1.CUSTOMER_NAME AS END_USAGE,
               gol.LOB,
               goh.TOTAL_MARGIN_PCT,
               goh.TOTAL_DISCOUNT,
               goh.TOTAL_DISCOUNT_PCT
        FROM   APPS_JP.GEDIS_OFFER_HEADER goh,
               APPS_JP.GEDIS_ORDER_BUILDS gob,
               APPS_JP.GEDIS_ORDER_LINES gol,
               APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER gorc,
               APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER ship,
               APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER bill,
               APPS_JP.GEDIS_CUSTOMER gc,
               APPS_JP.GEDIS_CUSTOMER gc1,
               APPS_JP.GEDIS_CONTACT gct,
               APPS_JP.GEDIS_ADDRESS ga,
               APPS_JP.GEDIS_ADDRESS_NORM ga1,
               APPS_JP.GEDIS_ADDRESS_NORM ga2,
               (SELECT   DISTINCT SALESPERSON_ID, USER_NAME
                  FROM   APPS_JP.GEDIS_SALESPERSON
                 WHERE   SALESPERSON_ID IN
                               (SELECT   TO_NUMBER (COLUMN_VALUE) AS SALESPERSON_ID
                                  FROM   TABLE (APPS_GLOBAL.SplitString ('337309'))))
               gsp
       WHERE       goh.ORDER_NO <> 0
               AND goh.OFFER_NO <> 0
               AND goh.OFFER_NO=gol.OFFER_NO
               AND gol.BUILD_NO = 1
               AND gol.LINE_NO = 1
               AND goh.OFFER_NO=gob.OFFER_NO
               AND gob.BUILD_NO = 1
               AND goh.OFFER_NO = gorc.OFFER_NO
               AND gct.CONTACT_ID = gorc.CONTACT_ID
               AND ga.CUSTOMER_ID = gc.CUSTOMER_ID
               AND ga.PRIMARY = 'Y'
               AND goh.LEAD_SALESPERSON=gsp.SALESPERSON_ID
               AND goh.OFFER_NO = ship.OFFER_NO
               AND ship.RELATION_TYPE = 'SHIP'
               AND ga1.ADDRESS_ID = ship.ADDRESS_ID
               AND ga1.CUSTOMER_ID = gc1.CUSTOMER_ID
               AND goh.OFFER_NO = bill.OFFER_NO
               AND bill.RELATION_TYPE = 'BILL'
               AND ga2.ADDRESS_ID = bill.ADDRESS_ID
               AND goh.OFFER_DATE BETWEEN APPS_JP.TZ.LOCAL_TO_DB_DATE (
                                             SYSDATE - 30
                                      AND  APPS_JP.TZ.LOCAL_TO_DB_DATE (SYSDATE)
               AND gorc.RELATION_TYPE = 'BASE'
               AND gorc.CUSTOMER_ID = gc.CUSTOMER_ID
               AND goh.SALES_CHANNEL = gc.SALES_CHANNEL
               AND gc.SALES_CHANNEL = 'SMB'
               AND goh.LEAD_SALESPERSON IN (goh.CREATED_BY, goh.LEAD_SALESPERSON)
    ORDER BY   goh.OFFER_NO;[/code]
    Please help me how to use this outer join condition.
    Thanks in advance.

    Hi,
    If you want all the rows from goh, then you don't want any conditions like  goh.OFFER_NO <> 0.
    Make all the joins to goh outer joins, and make all conditions that apply to any tables joined to goh (or to tables joined to them) part of the join condition, like this:
    FROM             APPS_JP.GEDIS_OFFER_HEADER     goh
    LEFT OUTER JOIN  APPS_JP.GEDIS_ORDER_BUILDS     gob  ON   gob.OFFER_NO = goh.OFFER_NO
                                                         AND  gob.BUILD_NO = 1
    LEFT OUTER JOIN  APPS_JP.GEDIS_ORDER_LINES      gol  ON   gol.OFFER_NO = goh.OFFER_NO
                                                         AND  gol.BUILD_NO = 1
                                                         AND  gol.LINE_NO  = 1
    LEFT OUTER JOIN  APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER
                                                    gorc ...
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Simplify the problem as much as possible.  For example, do you really need all those tables to show what the problem is?  Of course, you need them in tyour real query, but if you understand a solution that only involves 4 or 5 tables, you'll know how to apply it to any number of tables.
    Explain, using specific examples, how you get those results from that data.Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ https://forums.oracle.com/message/9362002#9362002

  • How to achieve parent-child relationship using self join?

    my table structure is as follows
    parent child name
    -1     1     A1
    1     2     A2
    1     3     A3
    how to achieve the hierarchy model using self join. this can be easily achieved using "connect by prior". but how to achieve the same using self join?

    Hi,
    Yes, that's definitely possible. If you only need to display two levels from the hierarchy, a self-join is a good option. Make it an outer join if you need to show everyone on one level, regardless of whether they have a match on the other level or not; for example, if you want the output:
    child_name     child_id     parent_name     parent_id
    A1          1
    A2          2          A1          1
    A3          3          A1          1It's good that you posted some sample data. Now post the results you want from that data, and your query (what you think is the best attempt you've made so far). If you haven't tried anything so far, then look at some other simple self-join to get ideas.

  • Using Table.Join formula takes extremly long time to get results.(Why Query Folding doesn't work?)

    Hi,
    I built a query with 4 tables inside (load from Oracle DB and two of them are quite big, more than millions of rows). After filtering, I tried to build relationships between tables using Table.Join formula. However, the process took extremly long time to
    bring out results (I ended the process after 15 mins' processing). There's a status bar kept updating while the query was processing, which is showed as  . I suppose
    this is because the query folding didn't working, so PQ had to load all the data to local memory first then do the opertion, instead of doing all the work on the source system side. Am I right? If yes, is there any ways to solve this issue?
    Thanks.
    Regards,
    Qilong 

    Hi Curt,
    Here's the query that I'm refering,
    let
        Source = Oracle.Database("reporting"),
        AOLOT_HISTS = Source{[Schema="GEN",Item="MVIEW$_AOLOT_HISTS"]}[Data],
        WORK_WEEK = Source{[Schema="GEN",Item="WORK_WEEK"]}[Data],
        DEVICES = Source{[Schema="GEN",Item="MVIEW$_DEVICES"]}[Data],
        AO_LOTS = Source{[Schema="GEN",Item="MVIEW$_AO_LOTS"]}[Data],
        Filter_WorkWeek = Table.SelectRows(WORK_WEEK, each ([WRWK_YEAR] = 2015) and (([WORK_WEEK] = 1) or ([WORK_WEEK] = 2) or ([WORK_WEEK] = 3))), 
        Filter_AlotHists = Table.SelectRows(AOLOT_HISTS, each ([STEP_NAME] = "BAKE" or [STEP_NAME] = "COLD TEST-IFLEX" or [STEP_NAME] = "COLD TEST-MFLEX") and ([OUT_QUANTITY] <> 0)),
        #"Added Custom" = Table.AddColumn(Filter_AlotHists, "Custom", each Table.SelectRows(Filter_WorkWeek, (table2Row) => [PROCESS_END_TIME] >= table2Row[WRWK_START_DATE] and [PROCESS_END_TIME] <= table2Row[WRWK_END_DATE])),
        #"Expand Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"WRWK_YEAR", "WORK_WEEK", "WRWK_START_DATE", "WRWK_END_DATE"}, {"WRWK_YEAR", "WORK_WEEK",
    "WRWK_START_DATE", "WRWK_END_DATE"}),
        Filter_AolotHists_byWeek = Table.SelectRows(#"Expand Custom", each ([WORK_WEEK] <> null)),
        SelectColumns_AolotHists = Table.SelectColumns(Filter_AolotHists_byWeek,{"ALOT_NUMBER", "STEP_NAME", "PROCESS_START_TIME", "PROCESS_END_TIME", "START_QUANTITY", "OUT_QUANTITY", "REJECT_QUANTITY",
    "WRWK_FISCAL_YEAR", "WRWK_WORK_WEEK_NO"}),
        Filter_Devices= Table.SelectRows(DEVICES, each ([DEPARTMENT] = "TEST1")),
        SelectColumns_Devices = Table.SelectColumns(Filter_Devices,{"DEVC_NUMBER", "PCKG_CODE"}),
        Filter_AoLots = Table.SelectRows(AO_LOTS, each Text.Contains([DEVC_NUMBER], "MC09XS3400AFK") or Text.Contains([DEVC_NUMBER], "MC09XS3400AFKR2") or Text.Contains([DEVC_NUMBER], "MC10XS3412CHFK") or Text.Contains([DEVC_NUMBER],
    "MC10XS3412CHFKR2")),
        SelectColumns_AoLots = Table.SelectColumns(Filter_AoLots,{"ALOT_NUMBER", "DEVC_NUMBER", "TRACECODE", "WAFERLOTNUMBER"}),
        TableJoin = Table.Join(SelectColumns_AolotHists, "ALOT_NUMBER", Table.PrefixColumns(SelectColumns_AoLots, "AoLots"), "AoLots.ALOT_NUMBER"),
        TableJoin1 = Table.Join(TableJoin, "AoLots.DEVC_NUMBER", Table.PrefixColumns(SelectColumns_Devices, "Devices"), "Devices.DEVC_NUMBER")
    in
        TableJoin1
    Could you please give me some hints why it needs so long to process?
    Thanks.

  • How to use INNER JOIN in such case

    when i program as below[CASE1]. the code is able to active.
    CASE1:
    ==========================
    DATA: WK_BUKRS LIKE T001-BUKRS,
          WK_BUTXT LIKE T001-BUTXT,
          WK_TABLE(4) TYPE C VALUE 'T001'.
    START-OF-SELECTION.
      WK_BUKRS = 'DECN'.
      PERFORM GET_BUTXT USING WK_BUKRS WK_TABLE
                     CHANGING WK_BUTXT.
      WRITE: WK_BUTXT.
      FORM GET_BUTXT USING I_BUKRS LIKE T001-BUKRS
                           I_TABLE
                  CHANGING O_BUTXT LIKE T001-BUTXT.
        SELECT SINGLE BUTXT
                 INTO O_BUTXT
                 FROM (I_TABLE)
                WHERE BUKRS = I_BUKRS.
      ENDFORM.                   
    ===========================
    but when I need to INNER JOIN another table [CASE2]
    CASE2:
    =======================
    DATA: WK_BUKRS LIKE T001-BUKRS,
          WK_BUTXT LIKE T001-BUTXT,
          WK_TABLE(4) TYPE C VALUE 'T001'.
    START-OF-SELECTION.
      WK_BUKRS = 'DECN'.
      PERFORM GET_BUTXT USING WK_BUKRS WK_TABLE
                     CHANGING WK_BUTXT.
      WRITE: WK_BUTXT.
      FORM GET_BUTXT USING I_BUKRS LIKE T001-BUKRS
                           I_TABLE
                    CHANGING O_BUTXT LIKE T001-BUTXT.
        SELECT SINGLE BUTXT
                 INTO O_BUTXT
                 FROM (I_TABLE) AS G INNER JOIN BKPF AS H
                   ON GBUKRS = HBUKRS
                WHERE G~BUKRS = I_BUKRS.
      ENDFORM.          
    =================================
    Syntax error:
    Wrong expression "INNER" in FROM clause. WHERE condition.
    Can anybody help me to solve the problem.
    My requirement is to use INNER JOIN with variable table

    hi slam,
    chk this sample code.
    hi,
    table emp
    empno name
    a sasi
    b xxx
    c yyy
    table sal
    empno salary
    a 1000
    b 2000
    Inner join
    select eempno ename
    s~sal
    into table int_table
    from emp as e
    inner join sal as s
    on
    eempno = sempno.
    if you made inner join between table a and b by emp no
    the selection retrives only if the condition satisfy the output will be
    a sasi 1000
    b xxx 2000
    rgds
    anver
    if hlped mark points
    Message was edited by: Anversha s

  • How to use outer join in Corelated Update?

    Hi,
    I am using outer join in correlated update comand. But it is not updating the line which is not retrived from the query. Below is the example.
    Update model_table a
    Set a.model = (Select b.model_name from parts_table b
                        where b.model_id (+) = a.model_id)Check the above query and please let me know whether can user like this or not?
    Thanks

    Updating the values you want through subqueries is tricky. The correlated update should perform okay if the join columns are indexed but updating the correct rows may take some thought.
    You might need to add a WHERE clause to the update to use the subquery to only update the rows when the subquery return value is not null - if this is what you want. Something like
    Update model_table a
    Set a.model = (Select b.model_name from parts_table b
                        where b.model_id = a.model_id)
    where exists (Select b.model_name from parts_table b
                        where b.model_id = a.model_id)Edited by: riedelme on Jan 4, 2010 5:59 AM

  • How to use "full join" in ODI interface

    I need to join two tables using full join. So, when I drag and drop table columns (build join) and mark left and right join (get full join):
    +(All rows of OSS_NCELLREL (OSS_NCELLREL) including the rows unpaired with OSS_NECELASS (OSS_NECELASS) rows and all rows of OSS_NECELASS (OSS_NECELASS) incuding the rows unpaired with OSS_NCELLREL (OSS_NCELLREL)+
    I get the following error:
    Source panel of the diagram: Clause set to full join on a technology that does not support full joins
    I use Oracle DB tables in the same DB.
    Help! What I do wrong?

    Hi,
    You need to work around Topology Manager.
    Please follow the below steps,
    1. Edit the 'Oracle' technology from the Physical Architecture treeview.
    2. In the Technology Defintion Tab select 'Ordered (Sql ISO)' radio button.
    3. In the Technology 'SQL Tab' set the following:
    - Clause Location: From
    - Brackets supported in the ON clauses: check
    - Inner: check, type INNER JOIN
    - Cross: check, type CROSS JOIN
    - Left Outer: check, type LEFT OUTER JOIN
    - Right Outer: check, type RIGHT OUTER JOIN
    - Full Outer: check, type FULL OUTER JOIN
    PS: Please take a backup Oracle techno before editing. ;)
    Thanks,
    G
    Edited by: Gurusank on Nov 27, 2008 9:05 PM

  • How to use outer join on 3 tables

    how to use outer join on 3 tables
    say tables are mkpf,lips and vbrp
    mkpf-xblnr = lips-vbeln
    lips-vbeln  = vbrp-vgbel

    refer following querry
        select a~bukrs
               a~anln1
               a~ord42
               a~ord43
               b~afabe
               b~ndabj
               b~kaafa
               b~aafag
               c~kostl
               d~afasl
               d~ndjar
               d~ndper
        into corresponding fields of table gt_master
        from ( ( anla as a inner join anlc as b
        on abukrs = bbukrs
        and aanln1 = banln1
        and aanln2 = banln2 )
        inner join anlz as c
        on  abukrs = cbukrs
        and aanln1 = canln1
        and aanln2 = canln2 )
        inner join anlb as d
        on  abukrs = dbukrs
        and aanln1 = danln1
        and aanln2 = danln2
        where a~bukrs in s_comp.

  • Oracle query with out using self join

    hi friends,
    i have one table for exeample PERSTATUS
    pk/fK STUDENT NUMBER SUBJECT MARKS STATUS
    1 ACCOUNTS 15 RED
    1 MATHS 35 YELLOW
    1 SCINECE 45 GREEN
    2 ACCOUNTS 55 BROWN
    2 MATHS 35 YELLOW
    2 SCINECE 45 GREEN
    3 ACCOUNTS 15 RED
    3 MATHS 35 YELLOW
    3 SCINECE 45 GREEN
    i want students how status is both red and yellow so i am using self join
    i want students status is both red and yellow so i am using self join
    SELECT PS.STUDENTNUMBER,PS.STATUS,PS.STATUS1 FROM PERSTATUS PS ,PERSTATUS PS1
    WHERE PS.STUDENTNUMBER-PS1.STUDENTNUMER
    PS.STATUS='RED' AND PS1.STAUTS='YELLOW'
    i want students status is both RD and YELLOW AND GREEN so i am using self join( two self joinS}
    SELECT PS.STUDENTNUMBER,PS.STATUS,PS.STATUS,PS2.STATUS FROM PERSTATUS PS ,PERSTATUS PS1,PERSTATUS PS2
    WHERE PS.STUDENTNUMBER-PS1.STUDENTNUMER AND PS.STUDENTNUMBER-PS2.STUDENTNUMBER
    PS.STATUS='RED' AND PS1.STAUTS='YELLOW' AND PS2.STAUTUS='GREEN'
    if i require MORE STATUS then more self joins required, is there any alternative to achive this
    and if results comes in multiple rows are accepted (since with the above query result will come in single row)
    i tried to use group by (studentnumber,status) with status='red' and status='yellow'
    but it is not possible could you povidet he solution

    Hi,
    Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data, and the exact results you want from that data. Explain how you get those results from that data.
    See the forum FAQ {message:id=9360002}
    Here's an example of how to post the sample data:
    CREATE TABLE     perstatus
    (       studentnumber     NUMBER
    ,     subject          VARCHAR2 (10)
    ,     marks          NUMBER
    ,     status          VARCHAR2 (10)
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (1,           'ACCOUNTS', 15,       'RED');
    INSERT INTO perstatus (studentnumber, subject  ,  marks, status)
           VALUES           (1,           'MATHS',        35,       'YELLOW');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (1,           'SCINECE',  45,       'GREEN');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (2,           'ACCOUNTS', 55,       'BROWN');
    INSERT INTO perstatus (studentnumber, subject  ,  marks, status)
           VALUES           (2,           'MATHS',        35,       'YELLOW');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (2,           'SCINECE',  45,       'GREEN');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (3,           'ACCOUNTS', 15,       'RED');
    INSERT INTO perstatus (studentnumber, subject  ,  marks, status)
           VALUES           (3,           'MATHS',        35,       'YELLOW');
    INSERT INTO perstatus (studentnumber, subject,    marks, status)
           VALUES           (3,           'SCINECE',  45,       'GREEN');You were on the right track, thinking about GROUP BY. You're interested in something about the whole group of rows that has the same studentnumber. Looking at any individual row won't tell you if that row is part of the group you're interested in or not.
    If you want to see information about the group as a whole, you can do the whole job with GROUP BY. In this case, studnetnumber is the only thing that an entire group has in common. If you wanted to see the studentnumbers that had both RED and YELLOW, that is:
    STUDENTNUMBER
                1
                3here's one way you could do it:
    SELECT       studentnumber
    FROM       perstatus
    WHERE       status     IN ('RED', 'YELLOW')
    GROUP BY  studentnumber
    HAVING       COUNT (DISTINCT status) = 2  -- That is, both RED and YELLOW
    ORDER BY  studentnumber
    ;But say you wanted to see details about individuals in the group; for example, say we want to see all the columns for students that have all 3 of RED, YELLOW and GREEN, like this:
    STUDENTNUMBER SUBJECT         MARKS STATUS
                1 SCINECE            45 GREEN
                1 ACCOUNTS           15 RED
                1 MATHS              35 YELLOW
                3 SCINECE            45 GREEN
                3 ACCOUNTS           15 RED
                3 MATHS              35 YELLOWWe used the aggregate COUNT function earlier, but aggregate functions require collapsing the results down to one row per group.
    However, most of the aggregate functions, like COUNT, have analytic counterparts, that can give the same results without collapsing the result set. Here's one way to get the results above, using the analytic COUNT function:
    WITH     got_cnt          AS
         SELECT  studentnumber, subject, marks, status
         ,     COUNT ( DISTINCT CASE
                                   WHEN  status  IN ('RED', 'YELLOW', 'GREEN')
                             THEN  status
                               END
                    ) OVER (PARTITION BY  studentnumber)     AS cnt
         FROM    perstatus
    SELECT    studentnumber, subject, marks, status
    FROM       got_cnt
    WHERE       cnt  = 3
    ORDER BY  studentnumber
    ,            status
    ;

Maybe you are looking for

  • "do not have sufficient permissions to sync"

    My son has an iPod touch. My other son had a classic iPod for a while and I tried to point both their iPods at a shared library. I think that failed epically, and may be the cause of our later problems. Starting several months ago, #1 son couldn't sy

  • Socket read error: connection reset by peer

    Hi. Has anybody experienced the error message �Socket read error: connection reset by peer� Please see below for detailed information. Appreciate your help Regards RT Enviroment specification Server: HP/UX 11.00 64-bit, Oracle RDBMS 8.1.6.0.0 64-bit

  • Reading data from 2 infocubes in same start routine - RSDRI_INFOPROV_READ

    Hi guys, Is it possible to read data from 2 Infocubes via RSDRI_INFOPROV_READ FM in same start routine of Infosource. Both infocube have different KF's. my one Infocube reading is working fine but now need to another infocube in same strat routine. H

  • My PWM don't work after install new cooler...

    Hi... I have MSI P55-GD65 and i have a problem... My PWM don't work anymore   I had a Intel stock cooler and PWM on this cooler work nice (when is idle speed is about 2000 RPM, on load above 2500 and up RPM), but i buy Cooler Master Hyper TX3 (with 4

  • Help With Animating Over an AVI File!

    I have imported a 30 second avi clip into Flash and I am trying to create an animation over it. I've gathered that I need to create a new layer for the animation and I have drawn the object to animate but now when I press play, the timeline moves but