Join retrieving duplicate records

Can someone tell me why I am returning 10 records when there only should be one. I can put in a delete duplicates record after this but i would prefer to know what is wrong with the below. Tnks.
  SELECT MARAMATNR MARAPRDHA
         MAKTMAKTX T179TVTEXT
         APPENDING CORRESPONDING FIELDS OF TABLE GT_WK_STORAGE
         FROM MARA AS MARA
         INNER JOIN MAKT AS MAKT
         ON MARAMATNR EQ MAKTMATNR
         AND SPRAS EQ SY-LANGU
         INNER JOIN T179T AS T179T
         ON MARAPRDHA EQ T179TPRODH
         WHERE MARA~MATNR IN S_MATNR.

Hi,
I see one error in your code:
+FROM MARA AS MARA
INNER JOIN MAKT AS MAKT
ON MARAMATNR EQ MAKTMATNR
AND SPRAS EQ SY-LANGU+
how can you pretend to join tables MARA and MAKT with field SPRAS, when this field does not exist in MARA ??
I think you should modify your code this way:
SELECT MATNR PRDHA
into CORRESPONDING FIELDS OF GT_WK_STORAGE
from mara
WHERE MATNR IN S_MATNR.
SELECT single MAKTMAKTX T179TVTEXT
into CORRESPONDING FIELDS OF GT_WK_STORAGE
FROM makt inner join T179T
ON MAKTSPRAS EQ T179TSPRAS
WHERE MAKT~MATNR = GT_WK_STORAGE-MATNR
and   spras = sy-langu.
append GT_WK_STORAGE.
endselect.
Check the code, that I didn´t do it in SAP.

Similar Messages

  • How to avoid retrieve duplicate records from SalesLogix

    I wanted to know if you could assist me.  I am now responsible for reporting our inside sales activities which includes (each month), outbound calls made, opportunities created, opportunities won $, etc.  We use SalesLogix as our tool.  I have been working with Business Objects exporting this information from SalesLogix and have pretty much created the report I need.  The only problem I have is it will pull in duplicate records with the same opportunity ID number because my query is based on u201Ccampaign codesu201D attached to SLX opportunities.  When an opportunity is created in SLX, it automatically assigns an opportunity ID (ex: OQF8AA008YQB) which is distinctive.  However, when we attach more than one u201Ccampaign codeu201D to this opportunity it pulls in opportunity ID that many more times.
    Is there a way to filter or only retrieve one ID record number regardless of how many campaign codes are attached?  All the information attached to the opportunity are the same with the exception that the "campaign code" is different which makes it two records since I pull by "campaign code"
    My greatest appreciation!

    Hi,
    If you are having CAMPAIGN CODE in your query and if you are displaying it in your report, then it would definitely display multiple rows for OPPORTUNITY ID for each CAMPAIGN CODE it has. 
    If you would like to have just one row for OPPORTUNITY ID, then you will need to remove CAMPAIGN CODE from your report.

  • How to retrieve the duplicates records.

    Hi friends,
         My next issue, how to retrieve the duplicate records in web intelligence.I checked the option Retrieve duplicate records in web intelligence as well.But it is not helping me.
    Hope you guys are help to solve this issue.
    Thanks lot,
    Regards,
    -B-

    hi Blaji,,
    ive tried this here and it worked perfectly with me
    even so, you dont need to make the QTY as a dimension, you can leave it as a measure also, and it will work good with you.
    click the block on the WebI, the Block itself.
    and find its properties, under "Display", you will find
    "Avoid Duplicate row Aggregations"
    in the query it self you should flag "Retrieve Duplicated Rows"
    i think this will work fine with you
    good luck
    Amr

  • SQL Query to retrieve one line from duplicate records

    Hi
    I have one table which contains duplicate records in multiple column but the difference is in one column which contains the value 0 or positive. The query i want is to retrieve only the line with the positive value for only the duplicated records.
    here below a sample data for your reference:
    CREATE TABLE TRANS
      CALLTRANSTYPE     NVARCHAR2(6),
      ORIGANI                 NVARCHAR2(40),
      TERMANI                 NVARCHAR2(40),
      STARTTIME               DATE,
      STOPTIME                DATE,
      CELLID                  NVARCHAR2(10),
      CONNECTSECONDS          NUMBER,
      SWITCHCALLCHARGE        NUMBER
    INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:15:00','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:15:25','mm/dd/yyyy hh24:mi:ss'),null,25,0)
    INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:15:00','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:15:25','mm/dd/yyyy hh24:mi:ss'),null,25,18000)
    INSERT INTO TRANS VALUES ('REC','555988801','222242850',to_date('05/15/2012 09:18:03','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 09:18:20','mm/dd/yyyy hh24:mi:ss'),null,17,0)
    The output i want to have is:
    CALLTRANSTYPE     ORIGANI          TERMANI          STARTTIME          STOPTIME          CELLID          CONNECTSECONDS          SWITCHCALLCHARGE
    REC          555988801     222242850     05/15/2012 09:15:00     05/15/2012 09:15:25               25               18000
    REC          555988801     222242850     05/15/2012 09:18:03     05/15/2012 09:18:20               17               0 Thank you.

    Hi ekh
    this is the query i want to have, thank you for the help:
    SQL> Select *from
    select CALLTRANSTYPE,ORIGANI,TERMANI,STARTTIME,STOPTIME,CELLID,CONNECTSECONDS,SWITCHCALLCHARGE
    ,row_number() over( partition by     STARTTIME    ,STOPTIME order by    SWITCHCALLCHARGE DESC     ) rn from TRANS
    where rn=1;  
    CALLTR ORIGANI                                  TERMANI                                  STARTTIME STOPTIME  CELLID     CONNECTSECONDS SWITCHCALLCHARGE     RN
    REC    555988801                                222242850                                15-MAY-12 15-MAY-12                        25            18000      1
    REC    555988801                                222242850                                15-MAY-12 15-MAY-12                        17                0      1Regrads
    Lucienot.

  • How to tune the query for duplicate records while joining the two tables

    hi,i am executing the query which has retrieving multiple tables,in which one of them has duplicate record,how to get single record

    Not enough info...subject says "tune" the query, message says "write" the query...and where is actual query that you had tried ?

  • How to avoid Duplicate Records  while joining two tables

    Hi,
    I am trying to join three tables, basically two tables are same one is like history table, so I wrote a query like
    select
    e.id,
    e.seqNo,
    e.name,
    d.resDate,
    d.details
    from employees e,
    ((select * from dept)union(select * from dept_hist)) d
    join on d.id=e.id and e.seqno=d.seqno
    but this returing duplicate records.
    Could anyone please tell me how to avoid duplicate records of this query.

    Actually it is like if the record is processed it will be moved to hist table, so both table will not have same records and I need the record from both the tables so i have done the union of both the tables, so d will have the union of both records.
    But I am getting duplicate records if even I am distinct.

  • Join without duplicates

    hello,
    i'm quite new to oracle and dbms in general, so please be patient ;)
    so here goes:
    i have two tables: people and cities
    my task: select all people who live in a city that has a 'z' in its name or where the city_id field is empty.
    so i thought i'd join the two tables and see what happens:
    select people.* from people, cities
    where (people.city_id = cities.city_id and cities.city_name like '%z%')
    or (people.city_id is null);
    the problem here is that there are duplicate records for the people who have no city_id. how can i change the where-clause in order to avoid this?
    i was told not to use distinct, union, intersect.
    greets and thx!

    Processing ...
    with people as (
         select 'a' as p_name,
              1 as city_id
         from dual
         union all
         select 'a' as name,
              1 as city_id
         from dual
    ), cities as (
         select 'z' as c_name,
              1 as city_id
         from dual
    select people.* from people, cities
    where (people.city_id = cities.city_id and
    cities.c_name like '%z%')
    or (people.city_id = cities.city_id (+) and
    people.city_id is null)
    Query finished, retrieving results...
    P_NAME                   CITY_ID               
    a                                               1
    a                                               1
    2 row(s) retrievedBye AlessandroThere are two different things here:
    1) duplicate records because source have the same duplicate records i.e. as in your case a, 1 two times
    2) duplicate records because join condition is too weak.
    Your query Alessandro had duplicates because of (1).
    OP original query have duplicates or triplicates or whatever else because he allowed cartesian product between peoples rows which haven't city_id and cities i.e. it was case (2)
    It is easier to spot if you select not only people.* but also city columns.
    Look what original query gives us:
    SQL> with people as (
      2    select 1 p_id, 'Live in z1' name, 1 c_id from dual
      3    union all
      4    select 2 p_id, 'Live in z2' name, 1 c_id from dual
      5    union all
      6    select 3, 'Dont live in z1', 2 from dual
      7    union all
      8    select 4, 'Dont live in z2', 2 from dual
      9    union all
    10    select 5, 'Dont live anywhere1', null from dual
    11    union all
    12    select 6, 'Dont live anywhere2', null from dual
    13  ),
    14  cities as (
    15    select 1 city_id, 'bzz' city_name from dual
    16    union all
    17    select 2 city_id, 'aaa' city_name from dual
    18    union all
    19    select 3 city_id, 'bbb' city_name from dual
    20  )
    21  select * from people, cities
    22  where (people.c_id = cities.city_id and cities.city_name like '%z%')
    23  or people.c_id is null
    24  /
                    P_ID NAME                                C_ID              CITY_ID CIT
                       1 Live in z1                             1                    1 bzz
                       2 Live in z2                             1                    1 bzz
                       5 Dont live anywhere1                                         1 bzz
                       6 Dont live anywhere2                                         1 bzz
                       5 Dont live anywhere1                                         2 aaa
                       6 Dont live anywhere2                                         2 aaa
                       5 Dont live anywhere1                                         3 bbb
                       6 Dont live anywhere2                                         3 bbbWe have all combinations between city rows and rows in people, which city_id is null.
    If source rows already have duplicates then there isn't any possibility to get rid of them just using joins. Then we need distinct, group by or some set operation.
    Gints Plivna
    http://www.gplivna.eu

  • How to delete duplicate records in all tables of the database

    I would like to be able to delete all duplicate records in all the tables of the database. Many of the tables have LONG columns.
    Thanks.

    Hello
    To delete duplicates from an individual table you can use a construct like:
    DELETE FROM
        table_a del_tab
    WHERE
        del_tab.ROWID <> (SELECT
                                MAX(dups_tab.ROWID)
                          FROM
                                table_a dups_tab
                          WHERE
                                dups_tab.col1 = del_tab.col1
                          AND
                                dups_tab.col2 = del_tab.col2
                          )You can then apply this to any table you want. The only differences will be the columns that you join on in the sub query. If you want to look for duplicated data in the long columns themselves, I'm pretty sure you're going to need to do some PL/SQL coding or maybe convert them to blobs or something.
    HTH
    David

  • Joining 2 related records using PL SQL in Apex - Problems when there are more than 2 related records?

    Hi
    I am combining 2 related records of legacy data together that make up a marriage record.  I am doing this in APEX using a before header process using the following code below which works well when there are only 2 related records which joins the bride and groom record together on screen in apex.  I have appended a field called principle which is set to 'Y' for the groom and 'N' for the bride to this legacy data
    However there are lots of records where in some instances there are 3, 4 , 5, 6 or even 1 record which causes the PL/SQL in APEX to not return the correct data.  The difference in these related columns is that the name of the bride or groom could be different but it is the same person, its just that from the old system if a person had another name or was formally known as they would create another duplicate record for the marriage with the different name, but the book and entry number is the same as this is unique for each couple who get married.
    How can I adapt the script below so that if there are more than 2 records that match the entry and book values then it will display a message or is there a better possible work around?  Cleaning the data would be not an option as there are thousands of rows of where these occurrences occur
    declare 
         cursor c_mar_principle(b_entry in number, b_book in varchar2) 
         is 
              select DISTINCT  id, forename, surname, marriagedate, entry, book,  formername, principle
              from   MARRIAGES mar 
              where  mar.entry   = b_entry
              and    mar.book = b_book
              order by principle desc, id asc; 
         rec c_mar_principle%rowtype;
    begin 
    open c_mar_principle(:p16_entry,:p16_book)  ;
    fetch c_mar_principle into rec;
    :P16_SURNAME_GROOM   := rec.surname; 
    :P16_FORNAME_GROOM   := rec.forename;
                   :P16_ENTRY := rec.entry; 
                   :P16_BOOK :=rec.book;
    :P16_FORMERNAME :=rec.formername;
    :P16_MARRIAGEDATE :=rec.marriagedate;
    :P16_GROOMID  := rec.id;
    fetch c_mar_principle into rec;
    :P16_SURNAME_BRIDE   := rec.surname; 
    :P16_FORNAME_BRIDE   := rec.forename;
                   :P16_ENTRY := rec.entry; 
                   :P16_BOOK :=rec.book;
    :P16_FORMERNAME :=rec.formername;
    :P16_MARRIAGEDATE :=rec.marriagedate;
    :P16_BRIDEID  := rec.id;
    close c_mar_principle;
    end;

    rambo81 wrote:
    True but that answer is not really helping this situation either?
    It's indisputably true, which is more than can be said for the results of querying this data.
    The data is from an old legacy flat file database that has been exported into a relational database.
    It should have been normalized at the time it was imported.
    Without having to redesign the data model what options do I have in changing the PL/SQL to cater for multiple occurances
    In my professional opinion, none. The actual problem is the data model, so that's what should be changed.

  • Problem with duplicates record

    I have created an SAP_DataMart Fixed Query in SAP MII but I am getting duplicates records.
    Also, in my parameters settings I have  - PARAM.20 - 20140601  and PARAM.21  - 20140615 for dates
    Yet, I have the dates only displaying for 20140601 to 20140608?
    Please see attached part of a screenshot.
    Thank you.

    Hi Amr,
    It probably looks like an issue with the query itself. I suggest you verify the query by executing it directly in the source data system e.g in SAP using SQ01 and see if you get the same results.
    If yes, then it is a query join issue.
    Regards,
    Saumya Govil

  • Avoiding duplicate records while inserting into the table

    Hi
    I tried the following insert statement , where i want to avoid the duplicate records while inserting itself
    but giving me the errror like invalid identifier, though the column exists in the table
    Please let me know Where i'm doing the mistake.
    INSERT INTO t_map tm(sn_id,o_id,txt,typ,sn_time)
       SELECT 100,
              sk.obj_id,
              sk.key_txt,
              sk.obj_typ,
              sysdate,
              FROM S_KEY sk
        WHERE     sk.obj_typ = 'AY'
              AND SYSDATE BETWEEN sk.start_date AND sk.end_date
              AND sk.obj_id IN (100170,1001054)
               and   not exists  (select 1
                                                                   FROM t_map tm1 where tm1.O_ID=tm.o_id
                                                                        and tm1.sn_id=tm.sn_id
                                                                        and tm1.txt=tm.txt
                                                                        and tm1.typ=tm.typ
                                                                        and tm1.sn_time=tm.sn_time )

    Then
    you have to join the table with alias tml where is that ?do you want like this?
    INSERT INTO t_map tm(sn_id,o_id,txt,typ,sn_time)
       SELECT 100,
              sk.obj_id,
              sk.key_txt,
              sk.obj_typ,
              sysdate,
              FROM S_KEY sk
        WHERE     sk.obj_typ = 'AY'
              AND SYSDATE BETWEEN sk.start_date AND sk.end_date
              AND sk.obj_id IN (100170,1001054)
               and   not exists  (select 1
                                                                   FROM t_map tm where sk.obj_ID=tm.o_id
                                                                        and 100=tm.sn_id
                                                                        and sk.key_txt=tm.txt
                                                                        and sk.obj_typ=tm.typ
                                                                        and sysdate=tm.sn_time )

  • Duplicate Records in Details for ECC data source. Help.

    Hello. First post on SDN. I have been searching prior posts, but have come up empty. I am in the middle of creating a report linking directly into 4 tables in ECC 6.0. I am having trouble in getting either the table links set up correctly, or filtering out duplicate record sets that are being reporting in the details section of my report. It appears that I have 119 records being displayed, when the parameters values should only yeild 7. The details section is repeating the 7 records 17 times (there are 17 matching records for the parameter choices in one of the other tables which I think is the cause).
    I think this is due to the other table links for my parameter values. But, I need to keep the links the way they are for other aspects of the report (header information). The tables in question are using an Inner Join, Enforced Both, =. I tried the other link options, with no luck.
    I am unable to use the "Select Disctinct Records" option in the Database menu since this is not supported when connecting to ECC.
    Any ideas would be greatly appreciated.
    Thanks,
    Barret
    PS. I come from more of a Functional background, so development is sort of new to me. Take it easy on the newbie.

    If you can't establish links to bring back unique data then use a group to diplay data.
    Group report by a filed which is the lowest commom denominator.
    Move all fields into group footer and suppress Group header and details
    You will not be able to use normal summaries as they will count/sum all the duplicated data, use Running Totals instead and select evaluate on change of the introduced group
    Ian

  • Duplicate records in generic data source

    Hello,
    We have created a generic data source using a database view joing two tables MARA and MBEW.
    When we run the view in our DEV server, we get perfectly fine data. Now when run the same view in QA, we get duplicate records.
    Is it any thing to do with the CLIENT as in QA, we have 2 clients with same data.
    MARA     MANDT     =     MBEW     MANDT
    MARA     MATNR     =     MBEW     MATNR
    This is what I mention in JOIN Conditions.
    Hope I could explain my issue properly. Please HELP !
    Abhishek

    Please check the possibility of Multiple records for a given material in MBEW,as same material can be in multiple valuation areas
    More over you will be executing extraction in one client so it is very unlikely that you see data of the other client
    In dev normally we do not have good data to test so it seems like design is correct in dev

  • 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

  • Query Takes 43 seconds to  retrieve 650 records

    Hi,
    We have Query which takes 43 seconds to retrieve 650 records.We are on 10.2.0.4 version.Kindly Suggest me any changes is required.
    SELECT InstrumentID, MEGroupID, MessageSequence FROM TIBEX_msgseqbyinstrumentbymeid WHERE MEGroupID = 'ME1';
    PLAN_TABLE_OUTPUT
    Plan hash value: 1364023912
    | Id  | Operation                 | Name                        | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT          |                             |    25 |  1550 | 56585   (2)| 00:11:20 |
    |   1 |  HASH GROUP BY            |                             |    25 |  1550 | 56585   (2)| 00:11:20 |
    |*  2 |   HASH JOIN               |                             |  3272 |   198K| 56584   (2)| 00:11:20 |
    |*  3 |    TABLE ACCESS FULL      | TIBEX_INSTRUMENT            |   677 | 14894 |    18   (0)| 00:00:01 |
    |   4 |    VIEW                   |                             |  5689 |   222K| 56565   (2)| 00:11:19 |
    |   5 |     UNION-ALL             |                             |       |       |            |          |
    |   6 |      HASH GROUP BY        |                             |   614 | 11052 |  4587   (2)| 00:00:56 |
    |   7 |       TABLE ACCESS FULL   | TIBEX_QUOTE                 |   455K|  8008K|  4564   (1)| 00:00:55 |
    |   8 |      HASH GROUP BY        |                             |   108 |  1944 | 50283   (2)| 00:10:04 |
    |   9 |       TABLE ACCESS FULL   | TIBEX_ORDER                 |  4926K|    84M| 50001   (1)| 00:10:01 |
    |  10 |      HASH GROUP BY        |                             |    52 |   936 |     8  (13)| 00:00:01 |
    |* 11 |       TABLE ACCESS FULL   | TIBEX_EXECUTION             |   307 |  5526 |     7   (0)| 00:00:01 |
    |  12 |      HASH GROUP BY        |                             |     1 |    40 |     3  (34)| 00:00:01 |
    |* 13 |       TABLE ACCESS FULL   | TIBEX_TSTRADE               |     1 |    40 |     2   (0)| 00:00:01 |
    |  14 |      HASH GROUP BY        |                             |   396 |  7128 |    13   (8)| 00:00:01 |
    |  15 |       INDEX FAST FULL SCAN| IX_BESTEXREL                |  3310 | 59580 |    12   (0)| 00:00:01 |
    |  16 |      HASH GROUP BY        |                             |  1125 | 20250 |    12   (9)| 00:00:01 |
    |* 17 |       TABLE ACCESS FULL   | TIBEX_MERESUMEPRDTRANSITION |  1981 | 35658 |    11   (0)| 00:00:01 |
    |  18 |      HASH GROUP BY        |                             |     1 |    17 |     4  (25)| 00:00:01 |
    |  19 |       TABLE ACCESS FULL   | TIBEX_EDPUPDATEREJECT       |    10 |   170 |     3   (0)| 00:00:01 |
    |  20 |      HASH GROUP BY        |                             |  1126 | 32654 |   822   (1)| 00:00:10 |
    |  21 |       NESTED LOOPS        |                             |  8640 |   244K|   821   (1)| 00:00:10 |
    |  22 |        TABLE ACCESS FULL  | TIBEX_INSTRUMENTADMIN       | 17280 |   421K|   820   (1)| 00:00:10 |
    |* 23 |        INDEX UNIQUE SCAN  | XPKTIBEX_CONFIGMEGROUP      |     1 |     4 |     0   (0)| 00:00:01 |
    |  24 |      HASH GROUP BY        |                             |    17 |   306 |    70   (3)| 00:00:01 |
    |  25 |       TABLE ACCESS FULL   | TIBEX_BESTEXECPRICELOG      | 12671 |   222K|    68   (0)| 00:00:01 |
    |  26 |      HASH GROUP BY        |                             |     1 |    40 |     3  (34)| 00:00:01 |
    |* 27 |       TABLE ACCESS FULL   | TIBEX_AUCTIONPRICE          |     1 |    40 |     2   (0)| 00:00:01 |
    |  28 |      HASH GROUP BY        |                             |  1126 | 19142 |   618   (1)| 00:00:08 |
    |* 29 |       TABLE ACCESS FULL   | TIBEX_ADMINACK              | 18121 |   300K|   616   (1)| 00:00:08 |
    |  30 |      HASH GROUP BY        |                             |  1122 | 20196 |   142   (2)| 00:00:02 |
    |  31 |       INDEX FAST FULL SCAN| INSTRUMENTSTATEMSGSEQ       | 23588 |   414K|   140   (0)| 00:00:02 |
    Predicate Information (identified by operation id):
       2 - access("INSTRUMENTID"="B"."INSTRUMENTID")
       3 - filter("B"."MEGROUPID"='ME1')
      11 - filter("INSTRUMENTID" IS NOT NULL)
      13 - filter("INSTRUMENTID" IS NOT NULL)
      17 - filter("INSTRUMENTID" IS NOT NULL)
      23 - access("ADMINUSER"="MEGROUPID")
      27 - filter("INSTRUMENTID" IS NOT NULL)
      29 - filter("INSTRUMENTID" IS NOT NULL)
    50 rows selected.
    654 rows selected.
    Elapsed: 00:00:43.67
    CREATE OR REPLACE VIEW TIBEX_MSGSEQBYINSTRUMENTBYMEID
    (INSTRUMENTID, MESSAGESEQUENCE, MEGROUPID)
    AS
    SELECT  a.*, b.megroupid
        FROM  TIBEX_MSGSEQBYINSTRUMENT a
        JOIN  tibex_instrument b
          ON  a.instrumentid=b.instrumentid
    CREATE OR REPLACE VIEW TIBEX_MSGSEQBYINSTRUMENT
    (INSTRUMENTID, MESSAGESEQUENCE)
    AS
    SELECT instrumentID, NVL(max(MessageSequence),0) as MessageSequence
        FROM  (SELECT instrumentID, max(MessageSequence) as MessageSequence
                FROM  tibex_quote
                WHERE instrumentID IS NOT NULL
                GROUP BY instrumentID
              UNION ALL
              SELECT instrumentID, max(MessageSequence)
                FROM  tibex_order
                WHERE instrumentID IS NOT NULL
                GROUP BY instrumentID
              UNION ALL
              SELECT instrumentID, max(MessageSequence)
                FROM  tibex_execution
                WHERE instrumentID IS NOT NULL
                GROUP BY instrumentID
              UNION ALL
              SELECT instrumentID, max(MessageSequence)
                FROM  tibex_TsTrade
                WHERE instrumentID IS NOT NULL
                GROUP BY instrumentID
              UNION ALL
              SELECT instrumentID, max(MessageSequence)
                FROM  tibex_BestExRel
                WHERE instrumentID IS NOT NULL
                GROUP BY instrumentID
              UNION ALL
              SELECT instrumentID, max(MessageSequence)
                FROM  tibex_MeResumePrdTransition
                WHERE instrumentID IS NOT NULL
                GROUP BY instrumentID
              UNION ALL
              SELECT instrumentID, max(MessageSequence)
                FROM tibex_EDPUpdateReject
                WHERE instrumentID IS NOT NULL
                  GROUP BY instrumentID
              UNION ALL
              SELECT  instrumentID, max(MessageSequence)
                FROM  tibex_INSTRUMENTADMIN
                WHERE instrumentID IS NOT NULL
                  AND adminuser IN (
                        SELECT  megroupID
                          FROM  tibex_configMeGroup
                GROUP by instrumentID
              UNION ALL
              SELECT instrumentID, max(MessageSequence)
                FROM tibex_BestExecPriceLog
                WHERE instrumentID IS NOT NULL
                GROUP BY instrumentID
              UNION ALL
              SELECT instrumentID, max(MessageSequence)
                FROM tibex_auctionPrice
                WHERE instrumentID IS NOT NULL
                GROUP BY instrumentID
              UNION ALL
              SELECT  instrumentID, max(AckMessageSequence)
                FROM  tibex_adminAck
                WHERE instrumentID IS NOT NULL
                GROUP BY instrumentID
              UNION ALL
              SELECT instrumentID, max(MessageSequence)
                FROM tibex_InstrumentState
                WHERE instrumentID IS NOT NULL
                GROUP BY instrumentID
        GROUP BY instrumentID
    /Regards
    Narasimha

    Hi,
    I dropped and recreated the stats without any modification(Eg adding new Indexes).The Query is hitting the indexes and it comes out in 00:00:16.86.But in the Production box the Same Query is doing Full tablescan.
    The only difference in producation and Test Env is I collected the Fresh stats but in prod Kindly read below and give me suggestion
    The Process Happens
    In the Beginning of the Day Following tables contains Like 100 records and as the day process it will reach 1,2,3,4 millions records by the EOD.During the EOD day we generate stats and delete those records and Tables will have 100 or 200 records but the stats will be for 4 Million records.Kindly Suggest me the best option
    tst_pre_eod@MIFEX3> set timing on
    tst_pre_eod@MIFEX3> show parameter user_dump_dest
    NAME                                 TYPE        VALUE
    user_dump_dest                       string      /u01/app/oracle/admin/MIFEX3/u
                                                     dump
    tst_pre_eod@MIFEX3>
    tst_pre_eod@MIFEX3> show parameter optimizer
    NAME                                 TYPE        VALUE
    optimizer_dynamic_sampling           integer     2
    optimizer_features_enable            string      10.2.0.4
    optimizer_index_caching              integer     0
    optimizer_index_cost_adj             integer     100
    optimizer_mode                       string      ALL_ROWS
    optimizer_secure_view_merging        boolean     TRUE
    tst_pre_eod@MIFEX3>
    tst_pre_eod@MIFEX3> show parameter db_file_multi
    NAME                                 TYPE        VALUE
    db_file_multiblock_read_count        integer     128
    tst_pre_eod@MIFEX3>
    tst_pre_eod@MIFEX3> show parameter db_block_size
    NAME                                 TYPE        VALUE
    db_block_size                        integer     8192
    tst_pre_eod@MIFEX3>
    tst_pre_eod@MIFEX3> show parameter cursor_sharing
    NAME                                 TYPE        VALUE
    cursor_sharing                       string      EXACT
    tst_pre_eod@MIFEX3>
    tst_pre_eod@MIFEX3> column sname format a20
    tst_pre_eod@MIFEX3> column pname format a20
    tst_pre_eod@MIFEX3> column pval2 format a20
    tst_pre_eod@MIFEX3>
    tst_pre_eod@MIFEX3> select
      2  sname
      3  , pname
      4  , pval1
      5  , pval2
      6  from
      7  sys.aux_stats$;
    SNAME                PNAME                     PVAL1 PVAL2
    SYSSTATS_INFO        STATUS                          COMPLETED
    SYSSTATS_INFO        DSTART                          01-11-2010 17:16
    SYSSTATS_INFO        DSTOP                           01-11-2010 17:16
    SYSSTATS_INFO        FLAGS                         1
    SYSSTATS_MAIN        CPUSPEEDNW           1489.10722
    SYSSTATS_MAIN        IOSEEKTIM                    10
    SYSSTATS_MAIN        IOTFRSPEED                 4096
    SYSSTATS_MAIN        SREADTIM                    .71
    SYSSTATS_MAIN        MREADTIM                 15.027
    SYSSTATS_MAIN        CPUSPEED                   2141
    SYSSTATS_MAIN        MBRC                         29
    SYSSTATS_MAIN        MAXTHR
    SYSSTATS_MAIN        SLAVETHR
    13 rows selected.
    Elapsed: 00:00:00.07
    tst_pre_eod@MIFEX3> set timing on
    tst_pre_eod@MIFEX3> explain plan for
      2
    tst_pre_eod@MIFEX3> SELECT InstrumentID, MEGroupID, MessageSequence FROM
      2           TIBEX_msgseqbyinstrumentbymeid WHERE MEGroupID = 'ME1';
    GLJd                                               ME1             2.9983E+18
    TALKl                                              ME1             2.9983E+18
    ENGl                                               ME1             2.9983E+18
    AGRl                                               ME1             2.9983E+18
    HHFAd                                              ME1             2.9983E+18
    GWI1d                                              ME1             2.9983E+18
    BIO3d                                              ME1             2.9983E+18
    603 rows selected.
    Elapsed: 00:00:16.72
    tst_pre_eod@MIFEX3> SELECT InstrumentID, MEGroupID, MessageSequence FROM
      2           TIBEX_msgseqbyinstrumentbymeid WHERE MEGroupID = 'ME1';
    603 rows selected.
    Elapsed: 00:00:16.86
    Execution Plan
    Plan hash value: 2206731661
    | Id  | Operation                   | Name                        | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |                             |    13 |   806 |   111K  (5)| 00:01:20 |
    |   1 |  HASH GROUP BY              |                             |    13 |   806 |   111K  (5)| 00:01:20 |
    |*  2 |   HASH JOIN                 |                             |  3072 |   186K|   111K  (5)| 00:01:20 |
    |*  3 |    TABLE ACCESS FULL        | TIBEX_INSTRUMENT            |   626 | 13772 |    28   (0)| 00:00:01 |
    |   4 |    VIEW                     |                             |  5776 |   225K|   111K  (5)| 00:01:20 |
    |   5 |     UNION-ALL               |                             |       |       |            |          |
    |   6 |      HASH GROUP BY          |                             |   782 | 14076 | 10056   (5)| 00:00:08 |
    |   7 |       TABLE ACCESS FULL     | TIBEX_QUOTE                 |   356K|  6260K|  9860   (3)| 00:00:08 |
    |   8 |      HASH GROUP BY          |                             |   128 |  2304 |   101K  (5)| 00:01:12 |
    |   9 |       VIEW                  | index$_join$_007            |  3719K|    63M| 98846   (3)| 00:01:11 |
    |* 10 |        HASH JOIN            |                             |       |       |            |          |
    |  11 |         INDEX FAST FULL SCAN| IX_ORDERBOOK                |  3719K|    63M| 32019   (3)| 00:00:23 |
    |  12 |         INDEX FAST FULL SCAN| TIBEX_ORDER_ID_ORD_INS      |  3719K|    63M| 24837   (3)| 00:00:18 |
    |  13 |      HASH GROUP BY          |                             |    23 |   414 |     4  (25)| 00:00:01 |
    |  14 |       VIEW                  | index$_join$_008            |   108 |  1944 |     3   (0)| 00:00:01 |
    |* 15 |        HASH JOIN            |                             |       |       |            |          |
    |  16 |         INDEX FAST FULL SCAN| TIBEX_EXECUTION_IDX1        |   108 |  1944 |     1   (0)| 00:00:01 |
    |* 17 |         INDEX FAST FULL SCAN| TIBEX_EXECUTION_IDX4        |   108 |  1944 |     1   (0)| 00:00:01 |
    |  18 |      HASH GROUP BY          |                             |     1 |    40 |     4  (25)| 00:00:01 |
    |* 19 |       TABLE ACCESS FULL     | TIBEX_TSTRADE               |     1 |    40 |     3   (0)| 00:00:01 |
    |  20 |      HASH GROUP BY          |                             |   394 |  7092 |    30  (10)| 00:00:01 |
    |  21 |       INDEX FAST FULL SCAN  | IX_BESTEXREL                |  4869 | 87642 |    28   (4)| 00:00:01 |
    |  22 |      HASH GROUP BY          |                             |  1126 | 20268 |    19  (11)| 00:00:01 |
    |* 23 |       TABLE ACCESS FULL     | TIBEX_MERESUMEPRDTRANSITION |  1947 | 35046 |    17   (0)| 00:00:01 |
    |  24 |      HASH GROUP BY          |                             |     1 |    17 |     7  (15)| 00:00:01 |
    |  25 |       TABLE ACCESS FULL     | TIBEX_EDPUPDATEREJECT       |     8 |   136 |     6   (0)| 00:00:01 |
    |  26 |      HASH GROUP BY          |                             |  1099 | 31871 |   192   (6)| 00:00:01 |
    |* 27 |       HASH JOIN             |                             |  6553 |   185K|   188   (4)| 00:00:01 |
    |  28 |        INDEX FULL SCAN      | XPKTIBEX_CONFIGMEGROUP      |     4 |    16 |     1   (0)| 00:00:01 |
    |  29 |        TABLE ACCESS FULL    | TIBEX_INSTRUMENTADMIN       | 14744 |   359K|   186   (4)| 00:00:01 |
    |  30 |      HASH GROUP BY          |                             |    11 |   198 |    77   (7)| 00:00:01 |
    |  31 |       TABLE ACCESS FULL     | TIBEX_BESTEXECPRICELOG      |  5534 | 99612 |    74   (3)| 00:00:01 |
    |  32 |      HASH GROUP BY          |                             |     1 |    40 |     4  (25)| 00:00:01 |
    |* 33 |       TABLE ACCESS FULL     | TIBEX_AUCTIONPRICE          |     1 |    40 |     3   (0)| 00:00:01 |
    |  34 |      HASH GROUP BY          |                             |  1098 | 18666 |   193   (7)| 00:00:01 |
    |* 35 |       TABLE ACCESS FULL     | TIBEX_ADMINACK              | 15836 |   262K|   185   (3)| 00:00:01 |
    |* 35 |       TABLE ACCESS FULL     | TIBEX_ADMINACK              | 15836 |   262K|   185   (3)| 00:00:01 |
    |  36 |      HASH GROUP BY          |                             |  1112 | 20016 |    76  (16)| 00:00:01 |
    |  37 |       INDEX FAST FULL SCAN  | INSTRUMENTSTATEMSGSEQ       | 20948 |   368K|    66   (4)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("INSTRUMENTID"="B"."INSTRUMENTID")
       3 - filter("B"."MEGROUPID"='ME1')
      10 - access(ROWID=ROWID)
      15 - access(ROWID=ROWID)
      17 - filter("INSTRUMENTID" IS NOT NULL)
      19 - filter("INSTRUMENTID" IS NOT NULL)
      23 - filter("INSTRUMENTID" IS NOT NULL)
      27 - access("ADMINUSER"="MEGROUPID")
      33 - filter("INSTRUMENTID" IS NOT NULL)
      35 - filter("INSTRUMENTID" IS NOT NULL)
    Statistics
            175  recursive calls
              0  db block gets
          57737  consistent gets
          18915  physical reads
              0  redo size
          14908  bytes sent via SQL*Net to client
            558  bytes received via SQL*Net from client
              8  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
            603  rows processed
    SELECT InstrumentID, MEGroupID, MessageSequence FROM
             TIBEX_msgseqbyinstrumentbymeid WHERE MEGroupID = 'ME1'
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.07          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        8     10.46      16.28      18915      57733          0         603
    total       10     10.47      16.35      18915      57733          0         603
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 303
    Rows     Row Source Operation
        603  HASH GROUP BY (cr=57733 pr=18915 pw=18900 time=16283336 us)
       2853   HASH JOIN  (cr=57733 pr=18915 pw=18900 time=281784 us)
        626    TABLE ACCESS FULL TIBEX_INSTRUMENT (cr=38 pr=0 pw=0 time=120 us)
       5594    VIEW  (cr=57695 pr=18915 pw=18900 time=278405 us)
       5594     UNION-ALL  (cr=57695 pr=18915 pw=18900 time=278400 us)
        823      HASH GROUP BY (cr=12938 pr=0 pw=0 time=272798 us)
    356197       TABLE ACCESS FULL TIBEX_QUOTE (cr=12938 pr=0 pw=0 time=41 us)
        136      HASH GROUP BY (cr=43989 pr=18915 pw=18900 time=15962878 us)
    3718076       VIEW  index$_join$_007 (cr=43989 pr=18915 pw=18900 time=13123768 us)
    3718076        HASH JOIN  (cr=43989 pr=18915 pw=18900 time=9405689 us)
    3718076         INDEX FAST FULL SCAN IX_ORDERBOOK (cr=24586 pr=0 pw=0 time=65 us)(object id 387849)
    3718076         INDEX FAST FULL SCAN TIBEX_ORDER_ID_ORD_INS (cr=19403 pr=0 pw=0 time=64 us)(object id 387867)
         23      HASH GROUP BY (cr=6 pr=0 pw=0 time=1265 us)
        108       VIEW  index$_join$_008 (cr=6 pr=0 pw=0 time=1024 us)
        108        HASH JOIN  (cr=6 pr=0 pw=0 time=914 us)
        108         INDEX FAST FULL SCAN TIBEX_EXECUTION_IDX1 (cr=3 pr=0 pw=0 time=155 us)(object id 386846)
        108         INDEX FAST FULL SCAN TIBEX_EXECUTION_IDX4 (cr=3 pr=0 pw=0 time=129 us)(object id 386845)
          0      HASH GROUP BY (cr=3 pr=0 pw=0 time=84 us)
          0       TABLE ACCESS FULL TIBEX_TSTRADE (cr=3 pr=0 pw=0 time=46 us)
        394      HASH GROUP BY (cr=39 pr=0 pw=0 time=2662 us)
       4869       INDEX FAST FULL SCAN IX_BESTEXREL (cr=39 pr=0 pw=0 time=22 us)(object id 386757)
       1126      HASH GROUP BY (cr=23 pr=0 pw=0 time=2338 us)
       1947       TABLE ACCESS FULL TIBEX_MERESUMEPRDTRANSITION (cr=23 pr=0 pw=0 time=29 us)
          1      HASH GROUP BY (cr=7 pr=0 pw=0 time=110 us)
          8       TABLE ACCESS FULL TIBEX_EDPUPDATEREJECT (cr=7 pr=0 pw=0 time=43 us)
        828      HASH GROUP BY (cr=249 pr=0 pw=0 time=6145 us)
        828       HASH JOIN  (cr=249 pr=0 pw=0 time=1008 us)
          4        INDEX FULL SCAN XPKTIBEX_CONFIGMEGROUP (cr=1 pr=0 pw=0 time=21 us)(object id 386786)
      14905        TABLE ACCESS FULL TIBEX_INSTRUMENTADMIN (cr=248 pr=0 pw=0 time=23 us)
         11      HASH GROUP BY (cr=99 pr=0 pw=0 time=3728 us)
       5556       TABLE ACCESS FULL TIBEX_BESTEXECPRICELOG (cr=99 pr=0 pw=0 time=32 us)
          0      HASH GROUP BY (cr=3 pr=0 pw=0 time=72 us)
          0       TABLE ACCESS FULL TIBEX_AUCTIONPRICE (cr=3 pr=0 pw=0 time=30 us)
       1126      HASH GROUP BY (cr=248 pr=0 pw=0 time=11102 us)
      16069       TABLE ACCESS FULL TIBEX_ADMINACK (cr=248 pr=0 pw=0 time=18 us)
       1126      HASH GROUP BY (cr=91 pr=0 pw=0 time=11947 us)
      21235       INDEX FAST FULL SCAN INSTRUMENTSTATEMSGSEQ (cr=91 pr=0 pw=0 time=38 us)(object id 386904)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       8        0.00          0.00
      direct path write temp                       1260        0.52          5.39
      direct path read temp                        1261        0.04          2.95
      SQL*Net message from client                     8        0.00          0.00
      SQL*Net more data to client                     6        0.00          0.00
    PARSE #8:c=15000,e=83259,p=0,cr=4,cu=0,mis=1,r=0,dep=0,og=1,tim=532014955506
    EXEC #8:c=1000,e=170,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=532014955744
    WAIT #8: nam='SQL*Net message to client' ela= 4 driver id=1413697536 #bytes=1 p3=0 obj#=572 tim=532014955794
    WAIT #8: nam='direct path write temp' ela= 4090 file number=201 first dba=84873 block cnt=15 obj#=572 tim=532015639268
    WAIT #8: nam='direct path write temp' ela= 2677 file number=201 first dba=84888 block cnt=15 obj#=572 tim=532015642558
    WAIT #8: nam='direct path write temp' ela= 20 file number=201 first dba=84903 block cnt=15 obj#=572 tim=532015652372
    WAIT #8: nam='direct path write temp' ela= 2190 file number=201 first dba=84918 block cnt=15 obj#=572 tim=532015656105
    WAIT #8: nam='direct path write temp' ela= 2247 file number=201 first dba=84933 block cnt=15 obj#=572 tim=532015659146
    WAIT #8: nam='direct path write temp' ela= 3386 file number=201 first dba=84948 block cnt=15 obj#=572 tim=532015662832
    WAIT #8: nam='direct path write temp' ela= 3375 file number=201 first dba=84963 block cnt=15 obj#=572 tim=532015666444
    WAIT #8: nam='direct path write temp' ela= 2796 file number=201 first dba=84978 block cnt=15 obj#=572 tim=532015670097
    WAIT #8: nam='direct path write temp' ela= 2901 file number=201 first dba=53129 block cnt=15 obj#=572 tim=532015673308
    WAIT #8: nam='direct path write temp' ela= 2933 file number=201 first dba=53144 block cnt=15 obj#=572 tim=532015676474
    WAIT #8: nam='direct path write temp' ela= 15 file number=201 first dba=53159 block cnt=15 obj#=572 tim=532015686479
    WAIT #8: nam='direct path write temp' ela= 2561 file number=201 first dba=53174 block cnt=15 obj#=572 tim=532015690084
    WAIT #8: nam='direct path write temp' ela= 2297 file number=201 first dba=53189 block cnt=15 obj#=572 tim=532015693299
    WAIT #8: nam='direct path write temp' ela= 3448 file number=201 first dba=53204 block cnt=15 obj#=572 tim=532015697026
    WAIT #8: nam='direct path write temp' ela= 2633 file number=201 first dba=53219 block cnt=15 obj#=572 tim=532015700114
    WAIT #8: nam='direct path write temp' ela= 2902 file number=201 first dba=53234 block cnt=15 obj#=572 tim=532015703743
    WAIT #8: nam='direct path write temp' ela= 3219 file number=201 first dba=53001 block cnt=15 obj#=572 tim=532015707190
    WAIT #8: nam='direct path write temp' ela= 2809 file number=201 first dba=53016 block cnt=15 obj#=572 tim=532015710215

Maybe you are looking for