Duplicate records in SQ00 query

HI,
I am trying to make a query joining 3 tables. All tables have atleast 1 key field in common. In the output I have all fields from the main table, 3 fields from table "B" with a left outer join and 1 field from table "C" with an inner join. I am recieving duplicate records in the output. Is this issue a result of incorrect join conditions or is something else needed. Below is an illustration of join conditions.
I look forward to your responses
Regards,
Curt

Curt - is this related to BI?
SQ00 is an ECC transaction and you may have better luck posting in one of the ERP spaces

Similar Messages

  • Duplicate Records in ABAP Query

    I have prepared ABAP query with tables KNA1, KNB1, BSID. I have mapped only BUKRS and KUNNR from BSID . as I don't have any condition to map the fields. I want only one record for considering  KUNNR and BUKRS in report . But in report It is displaying all entries from BSID considering BUKRS and KUNNR means for documents all line items.Kindly suggest as soon. How to avoid such duplicate records

    Hi,
    Duplicate Records in ABAP Query
    Regarding on your problem,
    Use these link, It will helps to your post
    ABAP Querry Duplicate entries
    Regards,
    Sekhar

  • 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

  • Duplicate records for Dynamic Query in WLS 7

    I am getting duplicate records back when I run a dynamic query. If I run the same
    query via a finder method, I get the correct results.
    Here's the query:
    SELECT DISTINCT OBJECT(a) FROM Company AS a, b IN a.userRole WHERE b.userId = ?1
    AND a.deptId IN ('1', '2', '3')
    Company EJB maps to LU_Company (look up table for company)
    Company to UserRole is a one-to-many relationship.
    The number of duplicates is equal to the number of records I have for the same company_id
    in User_Role table.
    The ids for the object I should get back are 1, 2, 3.
    Instead I get back 1, 1, 2, 2, 2, 2, 2, 3, 3, 3
    In the database, company_id 1 occurs twice in user_role table; company_id 2 occurs
    five times.
    Any ideas of why the dynamic query has this problem whereas the same query for a
    finder method works fine?
    Thanks for your help.

    Thanks Greg, that worked!
    "Greg Nyberg" <greg.nyberg.at.objectpartners.com> wrote:
    You can supply properties on the query request, perhaps there is a
    SQL_SELECT_DISTINCT property:
    Properties p = new Properties();
    p.setProperty("GROUP_NAME", "fieldgroup");
    p.setProperty("INCLUDE_UPDATES", "true");
    p.setProperty("SQL_SELECT_DISTINCT", "true");
    Collection people = myQuery.find(
    "SELECT OBJECT(o) FROM PersonCMPEJB o WHERE o.lastName = 'Smith'", p);
    -Greg
    Check out my WebLogic 6.1 Workbook for O'Reilly EJB Third Edition
    www.amazon.com/exec/obidos/ASIN/1931822468 or www.titan-books.com
    "Mike" <[email protected]> wrote in message
    news:[email protected]...
    Matt,
    <sql-select-distinct> needs to be set in <weblogic-query> element. I amgenerating
    a dynamic query from within a local client. So I don't have a finderdefined for
    this method. (I don't want to define a finder for this method). How doyou suggest
    I can use this? Thanks again for your help.
    Matthew Shinn <[email protected]> wrote:
    Hi Mike,
    I just filed a bug report for this (CR079471). As a work around, you
    can
    use the
    setSQLSelectDistinct flag so the database will weed out the duplicates.
    The only thing to
    look out for when using this flag is that Oracle will not allow the use
    of 'SELECT DISTINCT'
    in conjunction with a 'FOR UPDATE' clause, thus,<sql-select-distinct>True
    CANNOT be used if
    any Bean in the calling chain has a method with <transaction-isolation>
    set to
    <isolation-level>TRANSACTION_READ_COMMITTED_FOR_UPDATE. Sorry for theinconvenience.
    - Matt
    Mike wrote:
    I am getting duplicate records back when I run a dynamic query. If
    I
    run
    the same
    query via a finder method, I get the correct results.
    Here's the query:
    SELECT DISTINCT OBJECT(a) FROM Company AS a, b IN a.userRole WHERE
    b.userId
    = ?1
    AND a.deptId IN ('1', '2', '3')
    Company EJB maps to LU_Company (look up table for company)
    Company to UserRole is a one-to-many relationship.
    The number of duplicates is equal to the number of records I have forthe same company_id
    in User_Role table.
    The ids for the object I should get back are 1, 2, 3.
    Instead I get back 1, 1, 2, 2, 2, 2, 2, 3, 3, 3
    In the database, company_id 1 occurs twice in user_role table;
    company_id
    2 occurs
    five times.
    Any ideas of why the dynamic query has this problem whereas the same
    query
    for a
    finder method works fine?
    Thanks for your help.

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

  • How to delete duplicate record in Query report

    Hi Experts,
    I had created an infoset and query in my sap, but I want to delete some duplicate records before the list out put.Please can we add some further codes in the Extras code to delete duplicates? And how do it? Would you please give me a simple brief.
    Joe

    Hi,
    You can try to restrict in the filter area in query designer with the values for characteristic which gives correct
    result.
    But still i would suggest that in the cube you keep not the duplicate records as this is not your requirement and giving
    you wrong result.
    So you can reload the correct records in the cube inorder to avoid such problems even in future.
    Regards,
    Amit

  • Need a query for duplicate records deletion

    here is one scenario...
    23130 ----> 'A'
    23130 ----> 'X'
    23130 ----> 'c'
    These are duplicate records.. when we remove duplicates, the record must get 'c', if it contains A,C,X. If it contains A and X, then the record must get 'X'. That means the priority goes like this C-->X-->A. for this i need query.. this is one scenario. It would be great if u reply me asap.

    Hello
    It's great that you gave examples of your data, but it is quite helpful to supply create table and insert statements too along with a clear example of expected results. Anyway, I think this does what you are looking for.
    CREATE TABLE dt_dup (ID NUMBER, flag VARCHAR2(1))
    INSERT INTO dt_dup VALUES(23130, 'A');
    insert into dt_dup values(23130, 'X');
    insert into dt_dup values(23130, 'C');
    INSERT INTO dt_dup VALUES(23131, 'A');
    INSERT INTO dt_dup VALUES(23131, 'X');
    DELETE
    FROM
      dt_dup
    WHERE
      ROWID IN (  SELECT
                    rid
                  FROM
                    (   SELECT
                          rowid rid,
                          ROW_NUMBER() OVER (PARTITION BY ID ORDER BY CASE
                                                                        WHEN flag = 'A' THEN
                                                                          3
                                                                        WHEN flag = 'X' THEN
                                                                          2
                                                                        WHEN flag = 'C' THEN
                                                                          1
                                                                      END
                                            ) rn
                        FROM
                          dt_dup
                  WHERE
                    rn > 1
    select * from dt_dup;HTH
    David
    Edited by: Bravid on Jun 30, 2011 8:12 AM

  • Help with Finding Duplicate records Query

    HI,
    I am trying to write a query that will find duplicate records/cases.
    This query will be used in a report.
    So, here are the requirements:
    I need to find duplicate cases/records based on the following fields:
    DOB, DOCKET, SENT_DATEI was able to do that with the following query. The query below is able to give me all duplicate records based on the Criteria above
    SELECT      DEF.BIRTH_DATE DOB,
               S.DOCKET DOCKET,
               S.SENT_VIO_DATE SENT_DATE, COUNT(*)
    FROM SENTENCES S,
                DEFENDANTS DEF
    WHERE      S.DEF_ID = DEF.DEF_ID
    AND       S.CASE_TYPE_CODE = 10
    GROUP BY  DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE
    HAVING COUNT(*) > 1;
    //I AM GOING TO CALL THIS QUERY 'X'Now, the information to be displayed on the report: defendants Name, DOB, District, Docket, Def Num, Sent Date, and PACTS Num if possible.
    The problem that I need help on is how to combine those queries together (what I mean is a sub query). the 'X' query returns multiple values. please have a look at the comments on the query below to see what I'm trying to achieve.
    here is the main query:
    SELECT      INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
            DEF.BIRTH_DATE DOB,
            TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
            S.DOCKET DOCKET,
            S.DEF_NUM DEF_NUM,
            S.SENT_VIO_DATE SENT_DATE,
            DEF.PACTS_ID PACTS_NUM
    FROM      USSC_CASES.DEFENDANTS DEF,
            USSC_CASES.SENTENCES S,
            LOOKUP.DISTRICTS DIST
    WHERE      DEF.DEF_ID = S.DEF_ID
    AND      S.DIST_ID = DIST.USSC_DISTRICT_ID
    AND     S.CASE_TYPE_CODE = 10
    AND     S.USSC_ID IS NOT NULL
    AND // what i'm trying to do is: DOB, DOCKET, SENT_DATE IN ('X' QUERY), is this possible ??
    ORDER BY DEFENDANT_NAME; thanks in advance.
    I am using Oracle 11g, and sql developer.
    if my approach doesn't work, is there a better approach ?
    Edited by: Rooney on Jul 11, 2012 3:50 PM

    If I got it right, you want to join table USSC_CASES.DEFENDANTS to duplicate rows in USSC_CASES. If so:
    SELECT  INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
            DEF.BIRTH_DATE DOB,
            TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
            S.DOCKET DOCKET,
            S.DEF_NUM DEF_NUM,
            S.SENT_VIO_DATE SENT_DATE,
            DEF.PACTS_ID PACTS_NUM
      FROM  USSC_CASES.DEFENDANTS DEF,
             SELECT  *
               FROM  (
                      SELECT  S.*,
                              COUNT(*) OVER(PARTITION BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE) CNT
                        FROM  USSC_CASES.SENTENCES S
               WHERE CNT > 1
            ) S,
            LOOKUP.DISTRICTS DIST
      WHERE DEF.DEF_ID = S.DEF_ID
       AND  S.DIST_ID = DIST.USSC_DISTRICT_ID
       AND  S.CASE_TYPE_CODE = 10
       AND  S.USSC_ID IS NOT NULL
      ORDER BY DEFENDANT_NAME;If you want to exclude duplicates from the query and do not care which row out of duplicate rows to choose:
    SELECT  INITCAP(DEF.LAST_NAME) || ' ' || INITCAP(DEF.FIRST_NAME) || ' ' || INITCAP(DEF.MIDDLE_NAME) DEFENDANT_NAME,
            DEF.BIRTH_DATE DOB,
            TRIM(DIST.DISTRICT_NAME) DISTRICT_NAME,
            S.DOCKET DOCKET,
            S.DEF_NUM DEF_NUM,
            S.SENT_VIO_DATE SENT_DATE,
            DEF.PACTS_ID PACTS_NUM
      FROM  USSC_CASES.DEFENDANTS DEF,
             SELECT  *
               FROM  (
                      SELECT  S.*,
                              ROW_NUMBER() OVER(PARTITION BY DEF.BIRTH_DATE, S.DOCKET, S.SENT_VIO_DATE ORDER BY 1) RN
                        FROM  USSC_CASES.SENTENCES S
               WHERE RN = 1
            ) S,
            LOOKUP.DISTRICTS DIST
      WHERE DEF.DEF_ID = S.DEF_ID
       AND  S.DIST_ID = DIST.USSC_DISTRICT_ID
       AND  S.CASE_TYPE_CODE = 10
       AND  S.USSC_ID IS NOT NULL
      ORDER BY DEFENDANT_NAME;SY.

  • Select query-using Union All display duplicate records.

    Hello All Gurus-
    I am using Oracle 9.i
    When i use the following query to fetch the records based on BUILDNUMBERNAME and ASSIGNED_BUILD then i am getting duplicate records -
    select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6'
    Union All
    select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6'
    How can i use the order by on T1.ID ? When i use the Order by T1.ID then it throws some error.
    Kindly help me in this :(
    Thanks in advance.

    Sorry for not providing all of the details -
    I am using Toad tool to run the query.
    1-When i use the following query -
    Select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6' order by T1.ID
    Union All
    select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6' order by T1.ID
    ORA-00933: SQL command not properly ended.
    2-If i am not using the T1.ID and run the following query
    Select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1. ASSIGNED_BUILD like '1.4.5.6'
    Union All
    select T1.ID FROM Defect T1,statedef T2,repoproject T3
    WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name Like 'ABC' AND T1.BUILDNUMBERNAME like '1.4.5.6'
    Then it is running fine but it is displaying the duplicate values like -
    00089646
    00087780
    00089148
    00090118
    00090410
    00088503
    00080985
    00084526
    00087108
    00087109
    00087117
    00088778
    00086714
    00079518
    00087780
    00089148
    00090392
    00090393
    00090395
    00090398
    00090401
    00090402
    00090403
    00090406
    00090408
    00088503
    00080985
    00084526
    00087108
    00087109
    00087117
    00088778
    00086714
    00079518

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

  • Query creating duplicate records

    Hi
    I need to create a report that gives the po number, po line item number, material number and the delivery post code.
    I have created a query with the following tables:
    EKKO, EKPO, EBAN, VBEP, VBAK, VBPA, ADRC.
    I have deleted the wrong link between EKKO and EKPO and retained all other links as suggested.
    Could anybody let me know why there are duplicate records in the report pls?
    Thanks
    Desp09

    Desp09 wrote:
    Hi
    >
    > I have connected
    >
    > EKKO-EBELN to EKPO
    >
    >  EKPO -EBELN and EKPO-EBELP  to the same of EBAN
    >
    > also EKPO-BANFN and EKPO-BNFPO to the same of EBAN
    >
    > EBAN-BANFN and EBAN-BNFPO to VBEP
    >
    > VBEP-VBELN to VBAK-VBELn
    >
    > VBAK-VBELN to VBPA-VBELN
    >
    > VBPA-ADRNR to ADRC-ADDRNUMBER.
    >
    > This is the first time I have created a query so if you can kindly explain the logic of the error it would help in my future reports.
    >
    > Thanks
    > Priya
    Hi Priya,
    You can simplify the process if you make use of the LDB, which will fetch the same report with std LDB available in the system.
    You can define multiple infosets and  pull the fields for easier approach.
    Regards
    Shiva

  • Query to find out 2 columns duplicate records

    hi
    how can i find out duplicate records from a table with 2columns duplicated
    eg: emp_id, book_id duplicated together
    emp_id book_id
    001 A
    001 A
    001 B
    in this case query should return ( emp_id: 001 , book_id: A ) because these are duplicated together

    SQL> with t as
      2  (
      3  select 1 a,'A' b from dual
      4  union all
      5  select 1,'A' from dual
      6  union all
      7  select 1,'B' from dual
      8  )
      9  select distinct a,b
    10    from (
    11  select t.*,count(1) over (partition by a,b order by a) cnt
    12    from t)
    13   where cnt > 1
    14  /
             A B
             1 A
    SQL> with t as
      2  (
      3  select 1 a,'A' b from dual
      4  union all
      5  select 1,'A' from dual
      6  union all
      7  select 1,'B' from dual
      8  )
      9   select a,b
    10     from t
    11    group by a,b
    12   having count(*) > 1
    13  /
             A B
             1 A

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

  • Query to find duplicate records (Urgent!!!!)

    Hi,
    I have a to load data from a staging table to base table but I dont want to load data already present in the base table. Criteria to identify the duplicate data is thorugh a field say v_id and status_flag. If these two are the same in both staging and base table then that record must be rejected as a duplicate record.
    Kindly help me with the SQL which i need to use in a Procedure.
    Thanks

    Hello
    Another alternative would be to use MINUS if the table structures match:
    --Source rows the first 5 are in the destination table
    SQL> select * from dt_test_src;
    OBJECT_ID OBJECT_NAME
    101081 /1005bd30_LnkdConstant
    90723 /10076b23_OraCustomDatumClosur
    97393 /103a2e73_DefaultEditorKitEndP
    106075 /1048734f_DefaultFolder
    93337 /10501902_BasicFileChooserUINe
         93013 /106faabc_BasicTreeUIKeyHandle
         94929 /10744837_ObjectStreamClass2
        100681 /1079c94d_NumberConstantData
         90909 /10804ae7_Constants
        102543 /108343f6_MultiColorChooserUI
         92413 /10845320_TypeMapImpl
         89593 /10948dc3_PermissionImpl
        102545 /1095ce9b_MultiComboBoxUI
         98065 /109cbb8e_SpanShapeRendererSim
        103855 /10a45bfe_ProfilePrinterErrors
        102145 /10a793fd_LocaleElements_iw
         98955 /10b74838_SecurityManagerImpl
        103841 /10c906a0_ProfilePrinterErrors
         90259 /10dcd7b1_ProducerConsumerProd
        100671 /10e48aa3_StringExpressionCons
    20 rows selected.
    Elapsed: 00:00:00.00
    --Destination table contents
    SQL> select * from dt_test_dest
      2  /
    OBJECT_ID OBJECT_NAME
        101081 /1005bd30_LnkdConstant
         90723 /10076b23_OraCustomDatumClosur
         97393 /103a2e73_DefaultEditorKitEndP
        106075 /1048734f_DefaultFolder
         93337 /10501902_BasicFileChooserUINe
    Elapsed: 00:00:00.00
    --try inserting everything which will fail because of the duplicates
    SQL> insert into dt_test_dest select * from dt_test_src;
    insert into dt_test_dest select * from dt_test_src
    ERROR at line 1:
    ORA-00001: unique constraint (CHIPSDEVDL1.DT_TEST_PK) violated
    Elapsed: 00:00:00.00
    --now use the minus operator to "subtract" rows from the source set that are already in the destination set
    SQL> insert into dt_test_dest select * from dt_test_src MINUS select * from dt_test_dest;
    15 rows created.
    Elapsed: 00:00:00.00
    SQL> select * from dt_test_dest;
    OBJECT_ID OBJECT_NAME
        101081 /1005bd30_LnkdConstant
         90723 /10076b23_OraCustomDatumClosur
         97393 /103a2e73_DefaultEditorKitEndP
        106075 /1048734f_DefaultFolder
         93337 /10501902_BasicFileChooserUINe
         89593 /10948dc3_PermissionImpl
         90259 /10dcd7b1_ProducerConsumerProd
         90909 /10804ae7_Constants
         92413 /10845320_TypeMapImpl
         93013 /106faabc_BasicTreeUIKeyHandle
         94929 /10744837_ObjectStreamClass2
         98065 /109cbb8e_SpanShapeRendererSim
         98955 /10b74838_SecurityManagerImpl
        100671 /10e48aa3_StringExpressionCons
        100681 /1079c94d_NumberConstantData
        102145 /10a793fd_LocaleElements_iw
        102543 /108343f6_MultiColorChooserUI
        102545 /1095ce9b_MultiComboBoxUI
        103841 /10c906a0_ProfilePrinterErrors
        103855 /10a45bfe_ProfilePrinterErrors
    20 rows selected.You could use that in conjunction with the merge statement to exclude all trully duplicated rows and then update any rows that match on the id but have different statuses:
    MERGE INTO dest_table dst
    USING(     SELECT
              v_id,
              col1,
              col2 etc
         FROM
              staging_table
         MINUS
         SELECT
              v_id,
              col1,
              col2 etc
         FROM
              destination_table
         ) stg
    ON
         (dts.v_id = stg.v_id)
    WHEN MATCHED THEN....HTH

  • How to get rid of duplicate records generated frm hierarchical cube in sql?

    Hi All,
    database version 10gR2.
    I am trying to aggregated data for two hierarchical dimensions, specifically organization and products.
    I am using one ROLLUP for each dimension, which would be two ROLLUP in GROUP BY clause to do the aggregation for every level of organization and product that are in included in the hierarchy.
    the troubling part is that that products that have data in corresponding fact table are not always located at the lowest level (which is 6) of the product hierarchy.
    e.g.
    product_id                               level
    0/01/0101/010102/01010201    5                           -->01010201, at level 5 , has data in fact table
    0/01/0101/010103                   4                           -->010103, at level 4, has data in fact table as well
    0/02/0201/020102/02010203/0201020304/020102030405              6   --> at level 6,(lowest level) and has data in fact table     we have a flat product hierarchy stored in table as below:
    prod_id  up_code_1 up_code_2 up_code_3   up_code_4   up_code_5 up_code_6
    01010201     0     01     0101     010102     01010201      NULL
    010103     0     01     0101     010103     null             nulldue to the NULL in product in level 6 for 01010201, when i run the query below, one duplicate record will be generated.
    for 010103, there will be 2 duplicate records, and for 020102030405 will be none.
    Encounter the same issue with the organizational dimension.
    currently, I am using DISTINCT to get rid of the duplicate records, but I don`t feel right to do it this way.
    So, I wonder if there is a more formal and standard way to do this?
    select distinct ORG_ID, DAY_ID,  TRADE_TYPE_ID, cust_id, PRODUCT_ID, QUANTITY_UNIT, COST_UNIT, SOURCE_ID,
          CONTRACT_AMOUNT, CONTRACT_COST, SALE_AMOUNT,SALE_COST, ACTUAL_AMOUNT, ACTUAL_COST, TRADE_COUNT
    from (     
    select  coalesce(UP_ORG_ID_6, UP_ORG_ID_5, UP_ORG_ID_4, UP_ORG_ID_3, UP_ORG_ID_2, UP_ORG_ID_1) as ORG_ID,
          a.day_id as day_id,        
          a.TRADE_TYPE_ID as TRADE_TYPE_ID,
          a.CUST_ID,
          coalesce(UP_CODE_6, UP_CODE_5, UP_CODE_4, UP_CODE_3, UP_CODE_2, UP_CODE_1) as product_id,
          QUANTITY_UNIT,
          COST_UNIT,
          A.SOURCE_ID as SOURCE_ID,
          SUM(CONTRACT_AMOUNT) as CONTRACT_AMOUNT,
          SUM(CONTRACT_COST) as CONTRACT_COST,
          SUM(SALE_AMOUNT) as SALE_AMOUNT,
          SUM(SALE_COST) as SALE_COST,
          SUM(ACTUAL_AMOUNT) as ACTUAL_AMOUNT,
          SUM(ACTUAL_COST) as ACTUAL_COST,
          SUM(TRADE_COUNT) as TRADE_COUNT     
    from DM_F_LO_SALE_DAY a, DM_D_ALL_ORG_FLAT B, DM_D_ALL_PROD_FLAT D --, DM_D_LO_CUST E
    where a.ORG_ID=B.ORG_ID
          and a.PRODUCT_ID=D.CODE
    group by rollup(UP_ORG_ID_1, UP_ORG_ID_2, UP_ORG_ID_3, UP_ORG_ID_4, UP_ORG_ID_5, UP_ORG_ID_6),
          a.TRADE_TYPE_ID,
          a.day_id,
          A.CUST_ID,
          rollup(UP_CODE_1, UP_CODE_2, UP_CODE_3, UP_CODE_4, UP_CODE_5, UP_CODE_6),
          a.QUANTITY_UNIT,
          a.COST_UNIT,
          a.SOURCE_ID );Note, GROUPING_ID seems not help, at least i didn`t find it useful in this scenario.
    any recommendation, links or ideas would be highly appreciated as always.
    Thanks

    anyone ever encounter this kind of problems?
    any thought would be appreciated.
    thanks

Maybe you are looking for