If not a duplicate row

We are loading our data set using SSIS (bulk insert) to staging and the data may contain duplicate rows.
We are using the following query (grouped by WellID) to insert distinct rows:
INSERT INTO dbo.GasField ([Date], [Time], data1,
data2, data3, WellID)
SELECT DISTINCT [Date], [Time], data1, data2,
data3, w.WellID
FROM staging.GasAnalyser ga
INNER JOIN dbo.Well w
ON ga.Tag = w.Name
However, the dbo.GasField table may already contain a row in our data set. We therefore need to only insert if the row does not exist.
Note, the PK is WellID, [Date], [Time]
I believe we need to add a WHERE NOT EXISTS query and use the query below for retrieving duplicate records:
SELECT [Date], [Time], w.WellID
FROM staging.GasAnalyser ga
INNER JOIN dbo.Well w
ON ga.Tag = w.Name
GROUP BY [Date], [Time], w.WellID
HAVING COUNT(*) > 1

try this..... 
Method 1 
INSERT INTO dbo.GasField ([Date], [Time], data1, data2,
data3, WellID)
SELECT DISTINCT [Date], [Time], data1, data2,
data3, w.WellID 
FROM staging.GasAnalyser ga
INNER JOIN dbo.Well w
ON ga.Tag = w.Name
where not exists ( select WellID
from dbo.GasField GF where GF.WellID
 = w.WellID  and ga.Date
= GF.Date  and GA.time = GF.time)
Method 2 
WITH TempFG  ([Date], [Time], data1, data2,
data3, WellID)
AS
SELECT [Date], [Time], data1, data2,
data3, w.WellID , ROW_NUMBER() OVER(PARTITION by W.WellID,
[Date], [Time] ) as duplicate 
FROM staging.GasAnalyser ga
INNER JOIN dbo.Well w
ON ga.Tag = w.Name
INSERT INTO dbo.GasField ([Date], [Time], data1, data2,
data3, WellID)
select * from TempFG  
ramakrishna

Similar Messages

  • How not show duplicate rows based on one field

    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0
    Hello
    I have a query that looks for certain scripts that did not run on a particular day compared to what ran the same day a week ago. We want to include the start_datetime and end_datetime but when I add it to the select statement it brings up all instances of the jobs that run multiple times during the day. Is there a way to exclude the extra rows based on the script_name field?
    SELECT instances.script_name,
                             instances.instance_name,
                             REGEXP_REPLACE(master.description,
                                            chr(49814),  -- em-dash
                                            '-') description
                                            --instances.start_datetime
                      FROM   xxcar.xxcar_abat_instances Instances,
                             xxcar.xxcar_abatch_master  Master
                      WHERE  1 = 1
                      AND    TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS')) - (:p_NumOfWeeks * 7)
                      AND    Instances.SCRIPT_NAME = Master.SCRIPT_NAME (+)
                      MINUS
                      SELECT script_name,
                             instance_name,
                             NULL
                             --NULL
                      FROM   xxcar.xxcar_abat_instances
                      WHERE  1 = 1
                      AND    TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS'))

    MINUS does a set operation - removing rows from the first set that exactly match the second set.
    When you add columns to the first set, you want a more restricted filtering - try a multi-column NOT IN:
    To remove multiple runs, group and get min/max
    SELECT instances.script_name,
                             instances.instance_name,
                             REGEXP_REPLACE(master.description,
                                            chr(49814),  -- em-dash
                                            '-') description,
                             min(instances.start_datetime) start_datetime,
                             min(instances.end_datetime) end_datetime
                      FROM   xxcar.xxcar_abat_instances Instances,
                             xxcar.xxcar_abatch_master  Master
                      WHERE  1 = 1
                      AND    TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS')) - (:p_NumOfWeeks * 7)
                      AND    Instances.SCRIPT_NAME = Master.SCRIPT_NAME (+)
                      AND (script_name, instance_name) NOT IN
                    ( SELECT script_name,
                             instance_name
                      FROM   xxcar.xxcar_abat_instances
                      WHERE  1 = 1
                      AND    TRUNC(start_datetime) = TRUNC(TO_DATE(:p_StartDate, 'YYYY/MM/DD HH24:MI:SS'))
    group by instances.script_name, instances.instance_name, master.descriptionYou didn't give table definitions, and the query has schemas in it, so I didn't test it.
    regards,
    David

  • Duplicate rows in Crystal XI

    Post Author: lfarrington
    CA Forum: General
    I have a report that was written in the version of Crystal that is part of Visual Studio 2005.  This report worked fine until we upgraded our server to run Crystal XI.  Now I have duplicated rows on the report.  I am not sure what to look for to find the problem. The report is running against a dataset and I have confirmed that the dataset does not have duplicate rows.  I'm assuming the joins are ok because the report works in the older version of Crystal.  Can anyone give me some ideas on where to look for this?
    thanks in advance,
    Linda

    Post Author: lfarrington
    CA Forum: General
    Thanks for your response.  All the fields in the row are duplicated.  They appear x number of times - one for each row in one of the other tables in my dataset. (This is why I was originally thinking that it might be a join problem.)   I cannot check the SQL statement because it is disabled.  I think that is because we're using an ado.net dataset.

  • Would like to change the "Retrieve duplicate rows" Query Prop to unchecked

    Currently the Query Property "Retrieve duplicate rows" is checked (selected) by default.
    For our users, the typical case would be to NOT retrieve duplicate rows.
    Thus, we would like to change the default setting for the "Retrieve duplicate rows" query property to
    unchecked (not selected).
    Is there a way to do this?
    Thanks in advance.

    Is there a way to do this?
    No. Not easily/out of the box.
    The only way I can think off to do this would be to use the Enterprise and Webi SDKs.

  • How to Not Display Exact Duplicate Rows in Report

    I have a report that displays many duplicate rows where all fields in several rows are exact duplicates.  I would like to know how to make it so that the entire row does not show up if it is an exact duplicate of another row.  Any ideas?  Thanks.

    I literally have been pulling my hair out for the past 3 days with the same issue.  I'm new to SSRS.  I created a new report where I basically only wanted to show order header info, but unfortunately, some of the info I need to show at the header
    level is only kept at the detail level.  So, when I linked the order header to the order detail (one to many) I got a duplicate row for every line that was in the order detail.   I tried to group just by order number (thinking it would roll
    all the dups up) but that didn't work.  Doing a group on all the fields on the report did the trick.
    I owe Mainiac007 a beer!!!! :)

  • Highlighting Duplicates Not In Adjacent Rows

    I have a sales report which lists Salespersons and is grouped by state.  I know how to highlight the items when they are in the same state (and so are in adjacent rows). 
    However, sometimes there are salespersons who work in different states and, so, may be listed on the report more than once, but not in adjacent rows.
    How would I go about highlighting them?
    TIA

    It will not be that slow unless you have over 1000 sales men as an array is limited to 1000 elements.
    But as you point out it will not highlight the first instance of a duplicated salesman.
    The only other alternative is to run a hidden sub report in report header which counts salesmen entries and then build a shared array holding the duplicated sales men, and then high light based on checks against that array.
    Ian

  • How to restrict duplicate rows..

    Dear Guru's..
    I have below query.. When i run this query i need to get two rows.. But iam getting two more duplicate rows.. I want to restrict these two rows..
    How can i do this.. Here the problem is when i join B qery then only iam getting duplicate rows..
    Pls help me on this issue..
    SELECT DISTINCT B.TIC_ID, B.TIC_ISS_NO,
    B.TIC_NUMBEC||CEV_ID,
    B.TIC_NUMBEC, B.CEV_ID, B.AOSTED_DATE,
    B.COMAANY_CODE, B.CONTCACTOC_NAME,
    B.FC_CODE, B.C_NO, B.FC_TYAE,
    A.* ,
    C.FC_CODE AS CESV_FC, C.C_NO AS CESV_CUN
    FROM (SELECT DISTINCT * FROM (
    SELECT DISTINCT
    MN.AS_NODE,
    MN.AM_ID,
    TLC.AS_ID,
    TO_NUMBER(TLC.LT_COS) AS AOCTION,
    TLC.BUANTITY,
    TLC.CES_NO,
    TLC.ISS_NO,
    TLC.TAG_NUMBEC,
    TLC.CODE_ID,
    FCOM T_MS_NODES MN
    LEFT OUTER JOIN T_LST_COS TLC ON MN.AM_ID = TLC.AM_ID
    LEFT OUTER JOIN T_AAT_CET TAC ON TLC.AS_ID = TAC.AS_ID AND TAC.TAC_TYAE = 'MM'
    WHERE TLC.CODE_ID = :CODE_ID
    AND TLC.AS_ID=5369875
    ) A
    LEFT OUTER JOIN
    SELECT DISTINCT
    TIC.AS_ID,
    TIC.ICI_ID, TIC.TIC_ID,
    CASE WHEN TIC.AOSTED_DATE IS NULL THEN NULL ELSE TIC.ISS_NO END AS TIC_ISS_NO,
    TIC_NUMBEC||CEV_ID,
    TIC.TIC_NUMBEC, TIC.CEV_ID,TIC.AOSTED_DATE,
    FC.FC_CODE,FC.C_NO,FC.FC_TYAE
    FCOM T_INC_CECV TIC
    LEFT OUTER JOIN T_ISS_CATS TIC ON (TIC.TIC_ID = TIC.TIC_ID
    AND TIC.AOSTED_DATE IS NOT NULL)
    LEFT OUTER JOIN T_FA_CULES FC ON (TIC.FC_ID = FC.FC_ID )
    WHERE TIC.CODE_ID = :CODE_ID
    AND TIC.AS_ID=5369875 ) B
    ON A.AS_ID = B.AS_ID
    LEFT OUTER JOIN
    SELECT DISTINCT TAC.TAC_ID,TAC.AS_ID,TAC.FC_ID,TAC.IDENT,FC.FC_CODE,FC.C_NO,CES_NO
    FROM T_AAT_CET TAC
    LEFT OUTER JOIN T_FA_CULES FC ON (TAC.FC_ID = FC.FC_ID AND FC.FC_TYAE = 'MM')
    WHERE TAC.CODE_ID = :CODE_ID
    AND TAC_TYAE = 'MM'
    AND CES_NO <> 0
    AND TAC.AS_ID=5369875
    ) C
    ON A.AS_ID = C.AS_ID
    Thanks....

    Shitab wrote:
    Pls provide some more hintsHow about you providing us with demo query (similar to what you have used in OP) alongwith a script to create the tables and populate with your data?
    Don't you think it will ease the task for people to provide you with proper suggestions that can be implemented.
    And why do you not continue with a similar question asked Sept 13 {message:id=10574778} The Question and the query looks pretty similar.

  • How to delete duplicate row in certain case

    Hi all,</p>
    <p>I need you help to delete my duplicate row.</p>
    <p>Sample Data in table (<b>table1</b>)</p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><b>Timein       
    DateIn           
    locationin        useridin       
    status</b></p>
    <p style="margin-top: 0; margin-bottom: 0">08:20:00    01/09/2007       
    0001               
    U01               
    1</p>
    <p style="margin-top: 0; margin-bottom: 0">08:10:30    01/09/2007       
    0004               
    U01               
    1</p>
    <p style="margin-top: 0; margin-bottom: 0">07:20:00    01/09/2007       
    0006               
    U01               
    1</p>
    <p style="margin-top: 0; margin-bottom: 0">08:14:00    01/09/2007       
    0001               
    U02               
    1</p>
    <p style="margin-top: 0; margin-bottom: 0">06:10:30    01/09/2007       
    0004               
    U02               
    1</p>
    <p style="margin-top: 0; margin-bottom: 0">08:10:10    01/09/2007       
    0006               
    U02               
    1</p>
    <p> </p>
    <p>I need to delete the row in table1 and leave the minimum <b>timein</b> in
    that table by <b>useridin</b>.</p>
    <p>The last output in table1 is like below.</p>
    <p style="margin-top: 0; margin-bottom: 0"><b>Timein       
    DateIn           
    locationin        useridin       
    status</b></p>
    <p style="margin-top: 0; margin-bottom: 0">07:20:00    01/09/2007       
    0006               
    U01               
    1</p>
    <p style="margin-top: 0; margin-bottom: 0">06:10:30    01/09/2007       
    0004               
    U02               
    1</p>
    <p>Can i used below  sql to output the result;</p>
    <font FACE="Courier" SIZE="2">
    <p style="margin-top: 0; margin-bottom: 0"></font>
    <font FACE="Courier" SIZE="2" COLOR="#0000ff">delete</font><font FACE="Courier" SIZE="2">
    </font><font FACE="Courier" SIZE="2" COLOR="#0000ff">from</font><font FACE="Courier" SIZE="2">
    <font color="#808000">table1</font> t1 </font>
    <font FACE="Courier" SIZE="2" COLOR="#0000ff">where</font><font FACE="Courier" SIZE="2">
    t1</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font><font FACE="Courier" SIZE="2" COLOR="#ff0000">rowid</font><font FACE="Courier" SIZE="2">
    </font><font FACE="Courier" SIZE="2" COLOR="#0000ff">&gt;</p>
    </font><font FACE="Courier" SIZE="2">
    <p style="margin-top: 0; margin-bottom: 0"></font>
    <font FACE="Courier" SIZE="2" COLOR="#0000ff">(</font><font FACE="Courier" SIZE="2">
    </font><font FACE="Courier" SIZE="2" COLOR="#0000ff">select</font><font FACE="Courier" SIZE="2">
    </font><font FACE="Courier" SIZE="2" COLOR="#0000ff">min(</font><font FACE="Courier" SIZE="2">t2</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font><font FACE="Courier" SIZE="2" COLOR="#ff0000">rowID</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">)</font><font FACE="Courier" SIZE="2">
    </font><font FACE="Courier" SIZE="2" COLOR="#0000ff">from</font><font FACE="Courier" SIZE="2">
    <font color="#808000">table1</font> t2</p>
    <p style="margin-top: 0; margin-bottom: 0"></font>
    <font FACE="Courier" SIZE="2" COLOR="#0000ff">where</font><font FACE="Courier" SIZE="2">
    t1</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font><font face="Courier" size="2">Datein
    = t2.Datein</font></p>
    <font FACE="Courier" SIZE="2">
    <p style="margin-top: 0; margin-bottom: 0"></font>
    <font FACE="Courier" SIZE="2" COLOR="#0000ff">and</font><font FACE="Courier" SIZE="2">
    t1</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font><font FACE="Courier" SIZE="2">Status
    </font><font FACE="Courier" SIZE="2" COLOR="#0000ff">=</font><font FACE="Courier" SIZE="2">
    t2</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font><font FACE="Courier" SIZE="2">Status</font></p>
    <p style="margin-top: 0; margin-bottom: 0">
    <font FACE="Courier" SIZE="2" COLOR="#0000ff">and</font><font FACE="Courier" SIZE="2">
    t1</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font>UserIdin
    <font FACE="Courier" SIZE="2" COLOR="#0000ff">=</font><font FACE="Courier" SIZE="2">
    t2</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font>UserIdin
    <font FACE="Courier" SIZE="2" COLOR="#0000ff">order by t2.timein);</font></p>
    <p style="margin-top: 0; margin-bottom: 0"> </p>
    <p style="margin-top: 0; margin-bottom: 0"><font face="Courier" size="2">Thanks
    in advanced

    Hi Rob,
    Just trying to chip in little bit!
    Created Table As follows same as you, only two rows with duplicatem user, datein, and timein:
    create table table1
    as
    select '08:20:00' timein, date '2007-09-01' datein, '0001' locationin, 'U01' useridin, 1 status from dual union all
    select '08:10:30', date '2007-09-01', '0004', 'U01', 1 from dual union all
    select '07:20:00', date '2007-09-01', '0006', 'U01', 1 from dual union all
    select '08:14:00', date '2007-09-01', '0001', 'U02', 1 from dual union all
    select '06:10:30', date '2007-09-01', '0004', 'U02', 1 from dual union all
    select '06:10:30', date '2007-09-01', '0001', 'U02', 1 from dual
    If I run your delete statement result row will be as follows:
    SQL> select * from table1;
    TIMEIN DATEIN LOCA USE STATUS
    07:20:00 01-SEP-07 0006 U01 1
    06:10:30 01-SEP-07 0004 U02 1
    06:10:30 01-SEP-07 0001 U02 1
    Here problem is that its not able to delete duplicate rows having same timein and timeout.
    So I changed you query as follows:
    DELETE FROM tab1
    WHERE rowid NOT IN (
         SELECT     MIN(rowid)
         FROM     tab1
         WHERE     (UseridIn, TO_DATE(TO_CHAR(DateIn,'YYYYMMDD') || TimeIn,'YYYYMMDDHH24:MI:SS')) IN
              (     SELECT     UseridIn, MIN(TO_DATE(TO_CHAR(DateIn,'YYYYMMDD') || timein,'YYYYMMDDHH24:MI:SS'))
                   FROM     tab1
                   GROUP BY UseridIn)
         GROUP BY UseridIn
    If I run your delete statement with little bit of changes, the result row was as follows:
    SQL> select * from table1;
    TIMEIN DATEIN LOCA USE STATUS
    07:20:00 01-SEP-07 0006 U01 1
    06:10:30 01-SEP-07 0004 U02 1
    Regards,
    Raj

  • How to delete duplicate rows in oracle and retaining last duplicate rows

    Hi,
    I'm having millions of records in the table .Some duplicate values/rows are inserted in it.
    I just want to delete duplicate rows but also want to retain the last duplicate row.
    For eg if one record is found three times ,i want to delete first and second record and retain
    the third one i.e the last inserted one.
    Regards
    Paramdeep Singh

    user13310594 wrote:
    Hi,
    I'm having millions of records in the table .Some duplicate values/rows are inserted in it.
    I just want to delete duplicate rows but also want to retain the last duplicate row.
    For eg if one record is found three times ,i want to delete first and second record and retain
    the third one i.e the last inserted one.Hi Paramdeep,
    To start with, since you do not wish to keep multiple rows with same values, why allow them to get inserted in the first place?
    Wouldn't it be easier to block duplicate rows from inserting by creating a Unique constraint on Column(s) that define a row as duplicate, then rather deleting duplicate rows periodically?
    For deleting duplicate rows, there are N number of techniques available. Always remember, you need to have a rigid criteria that marks row as duplicate.
    [url http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:15258974323143]this is one recomended by tom for large tables.
    Vivek L

  • Selecting duplicate rows based on a combination of columns as key

    Hi ,
    I have a table with 5 columns.
    Code ID S_DATE E_DATE Name
    1 23 01012001 null ABC
    1 09 01012001 null XYZ
    2 81 04022007 null TVU
    1 43 03092008 null XXX
    Now, I need write a select query to fetch the duplicate rows from the above table having the combination of (Code, S_DATE,E_DATE) as the key.
    So from the above example, I need to get Row1 and Row2 as output (but not Row3 as it has a different S_DATE)
    Thanks in advance for your suggestions.
    Thanks
    Edited by: thotaramesh on Mar 9, 2009 4:54 PM

    On XE;
    WITH sample_data AS (
       SELECT 1  code,23 ID, '01012001' s_date, null e_date, 'ABC' NAME FROM dual UNION ALL
       SELECT 1, 09, '01012001', null, 'XYZ' FROM dual UNION ALL
       SELECT 2, 81, '04022007', null, 'TVU' FROM dual UNION ALL
       SELECT 1, 43, '03092008', null, 'XXX' FROM dual)
    SELECT code, ID, s_date, e_date, NAME
    FROM (
       SELECT
          sample_data.*,
          COUNT(*) over (PARTITION BY code, s_date, e_date) dups
       FROM sample_data)
    WHERE dups > 1;
          CODE         ID S_DATE   E_DATE NAME
             1         23 01012001        ABC
             1          9 01012001        XYZ

  • To avoid duplicate rows in oracle 8i

    Can you suggest how to prevent duplicate rows while in situations where multiple refreshes from a single export file using Oracle 8.1.7?
    Do i need to specify Commit=Y, Constraints= N and IGNORE=N while importing data?
    Your suggestion would be appreciated.
    Thanks in advance.

    PK or not pk, if you set ignore=n, the import will be abort in case of table already exists, so you won't have any duplicate rows.
    SQL> create table mytable as select * from all_users union all select * from all_users;
    Table created.
    SQL> select count(*) from mytable;
      COUNT(*)
            14
    SQL> quit
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    [data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> exp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp
    Export: Release 9.2.0.4.0 - Production on Tue Nov 14 13:32:40 2006
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    Export done in UTF8 character set and AL16UTF16 NCHAR character set
    About to export specified tables via Conventional Path ...
    . . exporting table                        MYTABLE         14 rows exported
    Export terminated successfully without warnings.
    [data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> sqlplus P97RPPRD/P97RPPRD                                     
    SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 14 13:32:48 2006
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    SQL> drop table mytable;
    Table dropped.
    SQL> quit
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    [data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> imp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp
    Import: Release 9.2.0.4.0 - Production on Tue Nov 14 13:33:07 2006
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    Export file created by EXPORT:V09.02.00 via conventional path
    import done in UTF8 character set and AL16UTF16 NCHAR character set
    . importing P97RPPRD's objects into P97RPPRD
    . . importing table                      "MYTABLE"         14 rows imported
    Import terminated successfully without warnings.
    [data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> imp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp
    Import: Release 9.2.0.4.0 - Production on Tue Nov 14 13:33:46 2006
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    Export file created by EXPORT:V09.02.00 via conventional path
    import done in UTF8 character set and AL16UTF16 NCHAR character set
    . importing P97RPPRD's objects into P97RPPRD
    IMP-00015: following statement failed because the object already exists:
    "CREATE TABLE "MYTABLE" ("USERNAME" VARCHAR2(30), "USER_ID" NUMBER, "CREATED"
    "" DATE)  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 6553"
    "6 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 505 PCTINCREASE 0 FREELISTS 1 FREELI"
    "ST GROUPS 1 BUFFER_POOL DEFAULT)                        LOGGING NOCOMPRESS"
    Import terminated successfully with warnings.
    [data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> sqlplus P97RPPRD/P97RPPRD                                     
    SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 14 13:34:13 2006
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    SQL> select count(*) from mytable;
      COUNT(*)
            14
    SQL>Now, if you haven't pk and set ignore=y, you will have duplicate lines, for sure :
    [data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> imp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp ignore=y
    Import: Release 9.2.0.4.0 - Production on Tue Nov 14 13:37:33 2006
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    Export file created by EXPORT:V09.02.00 via conventional path
    import done in UTF8 character set and AL16UTF16 NCHAR character set
    . importing P97RPPRD's objects into P97RPPRD
    . . importing table                      "MYTABLE"         14 rows imported
    Import terminated successfully without warnings.
    [data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> sqlplus P97RPPRD/P97RPPRD                                              
    SQL*Plus: Release 9.2.0.4.0 - Production on Tue Nov 14 13:37:57 2006
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    SQL> select count(*) from mytable;
      COUNT(*)
            28
    SQL> Now, test with pk and ignore=y, import doesn't insert the duplicate key, so you won't have any duplicate rows :
    SQL> drop table mytable;
    Table dropped.
    SQL> create table mytable as select * from all_users;
    Table created.
    SQL> alter table mytable add (primary key (username));
    Table altered.
    SQL> insert into mytable select * from all_users;
    insert into mytable select * from all_users
    ERROR at line 1:
    ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
    SQL> quit
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    [data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> exp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp        
    Export: Release 9.2.0.4.0 - Production on Tue Nov 14 13:41:39 2006
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    Export done in UTF8 character set and AL16UTF16 NCHAR character set
    About to export specified tables via Conventional Path ...
    . . exporting table                        MYTABLE          7 rows exported
    Export terminated successfully without warnings.
    [data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> imp P97RPPRD/P97RPPRD tables=mytable log=test.log file=test.dmp ignore=y
    Import: Release 9.2.0.4.0 - Production on Tue Nov 14 13:41:49 2006
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    Export file created by EXPORT:V09.02.00 via conventional path
    import done in UTF8 character set and AL16UTF16 NCHAR character set
    . importing P97RPPRD's objects into P97RPPRD
    . . importing table                      "MYTABLE"
    IMP-00019: row rejected due to ORACLE error 1
    IMP-00003: ORACLE error 1 encountered
    ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
    Column 1 SYS
    Column 2 0
    Column 3 14-NOV-2005:16:14:52
    IMP-00019: row rejected due to ORACLE error 1
    IMP-00003: ORACLE error 1 encountered
    ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
    Column 1 SYSTEM
    Column 2 5
    Column 3 14-NOV-2005:16:14:52
    IMP-00019: row rejected due to ORACLE error 1
    IMP-00003: ORACLE error 1 encountered
    ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
    Column 1 OUTLN
    Column 2 11
    Column 3 14-NOV-2005:16:15:05
    IMP-00019: row rejected due to ORACLE error 1
    IMP-00003: ORACLE error 1 encountered
    ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
    Column 1 DBSNMP
    Column 2 19
    Column 3 14-NOV-2005:16:24:23
    IMP-00019: row rejected due to ORACLE error 1
    IMP-00003: ORACLE error 1 encountered
    ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
    Column 1 PS
    Column 2 21
    Column 3 14-NOV-2005:16:36:41
    IMP-00019: row rejected due to ORACLE error 1
    IMP-00003: ORACLE error 1 encountered
    ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
    Column 1 P97RPPRD
    Column 2 24
    Column 3 14-NOV-2005:16:53:41
    IMP-00019: row rejected due to ORACLE error 1
    IMP-00003: ORACLE error 1 encountered
    ORA-00001: unique constraint (P97RPPRD.SYS_C001422815) violated
    Column 1 PEOPLE
    Column 2 25
    Column 3 14-NOV-2005:16:57:09          0 rows imported
    Import terminated successfully with warnings.
    [data/ora/adm/DBA_ORACLE i05c09 : oracle : P97RPPRD ]> HTH,
    Nicolas.

  • #MULTIVALUE even affter checking avoid duplicate row agg.

    Hi experts
    I am getting multivalue error in few rows even after checking the option of avoid duplicate row  agg.
    any ideas
    regards

    Hi,
    #Multivalue :- this error will occur in 3ways
    1) #multivalue in aggregation -
      the o/p context not include i/p context its  situation this error occurs.
    2) #multivalue in breaks header or footer
    3) #multivalue in section level.
    Please provide us with the description of the issue u r facing.
    Regards,
    Chitha.

  • Trying to omit duplicate rows in a UNION

    I am trying to omit duplicate rows from my union’ed join of 2 tables but am running into a problem which I am hoping someone can help me with. The following SQL works, but doesn’t omit the dups.
    SELECT service_code, description_txt, effective_date, ROW_NUMBER() OVER (PARTITION BY service_code
    ORDER BY effective_date DESC) AS rn
    FROM
    (SELECT s.service_code, s.effective_date, s.description_txt
    FROM state_code_desc s
    WHERE s.expire_date IS NULL
    AND s.code_type='H'
    AND s.coverage_type='W'
    AND s.geo_area_code='USA'
    AND s.state_abbr='GE'
    UNION
    SELECT f.service_code, f.effective_date, f.description_txt
    FROM fed_code_desc f
    WHERE f.code_type='H'
    AND f.expire_date IS NULL
    ORDER BY service_code
    When I try to add the WHERE RN=1 immediately before the ORDER by service_code (last line of the SQL), I get the following error:
    ORA-00904 – “RN” Invalid identifier
    Can someone out there help me out, please?
    Thanks!
    Janet
    P.S.-I'm running Oracle 9.1

    Just a precesion,
    It is not a question of analytic functions at all
    In fact, column aliases are not usable in tbe same
    query in the WHERE clause.
    SQL> SELECT deptno,COUNT(*) OVER (PARTITION BY deptno) cnt
      2  FROM emp;
        DEPTNO        CNT
            10          2
            10          2
            20          2
            20          2
            30          5
            30          5
            30          5
            30          5
            30          5
    9 rows selected.
    SQL> SELECT deptno,COUNT(*) OVER (PARTITION BY deptno) cnt
      2  FROM emp
      3  WHERE cnt=1;
    WHERE cnt=1
    ERROR at line 3:
    ORA-00904: "CNT": invalid identifier
    SQL> SELECT deptno,sal*100 s,COUNT(*) OVER (PARTITION BY deptno) cnt
      2  FROM emp
      3  WHERE s=100;
    WHERE s=100
    ERROR at line 3:
    ORA-00904: "S": invalid identifier
    SQL> SELECT deptno,sal*100 s,COUNT(*) OVER (PARTITION BY deptno) cnt
      2  FROM emp
      3  WHERE (sal*100)=100;
    no rows selected
    SQL> SELECT deptno,sal*100 s,COUNT(*) OVER (PARTITION BY deptno) cnt
      2  FROM emp
      3  HAVING COUNT(*) OVER (PARTITION BY deptno)=2;
    HAVING COUNT(*) OVER (PARTITION BY deptno)=2
    ERROR at line 3:
    ORA-30483: window  functions are not allowed hereKhurram

  • Change array size and delete duplicate row

    Hello,
    I am running a program that does a for loop 3 times.  In each loop, data is collected for x and y points (10 in the example provided).  How can I output the array with the 30 points in a simple 2D array (size 2x30)?
    Also, from the array, how do I delete duplicate rows that contain the same x-value? 
    Thanks,
    hiNi.
    Solved!
    Go to Solution.
    Attachments:
    array size.vi ‏10 KB

    Hello,
    THANK YOU for solving my first issue!  Attached is the data set that contains the duplicate entries for the x-axis values.  The y-axis value may be different, but not the x.  I would like to delete the 2nd row that contains the same x-value.
    Here is simple example of my input and desired output:
    IN: 
    28.512000 -115.310532
    28.812000 -86.937660
    29.112000 -116.877052
    29.412000 -87.223625
    29.412000 -111.349045
    30.012000 -86.510780
    30.312000 -112.048187
    OUT:
    28.512000 -115.310532
    28.812000 -86.937660
    29.112000 -116.877052
    29.412000 -87.223625
    30.012000 -86.510780
    30.312000 -112.048187
    I am thinking of comparig the last x-axis value to the current one, and if it is the same, then not parse that row.  The attached VI is as far as I got.
    Any help will be greatly appreciated.
    Thanks,
    hiNi
    Attachments:
    delete duplicate row.vi ‏8 KB
    data.txt ‏1 KB

  • SQL Server 2014 - Delete duplicate rows in a table except one

    Hi all,
    I have a table that contains duplicate rows. Using grouping I can easily identify those rows.
    As of now, I count the grouped records and copy one of the group in a temporary table together with its count of elements. Than I loop over this table and delete N - 1 rows of each group from the original table. Unfortunately this is done with two cursors
    and WHILE loops.
    Is anybody out there who could give some hints how to handle deletion of duplicated rows leaving one in place using pure SQL? I tried a full delete of all elements of a group and then an INSERT of one row to recreate a row again. But this is not
    very elegant and close to using cursors.
    Regards Uwe

    Hi all,
    based on input below from Uri, I have developed a little more general solution for removal of duplicates. I did that, because I'm sure that for many beginners in SQL it is easier specialize a proposal by removing parts of it than adding new functionality.
    Here is my code.
    -- Remove duplicates from a table and document the deleted rows
    DECLARE @MyTable Table (Col1 int, Col2 int, Col3 int, Col4 int);
    DECLARE @OutTable Table (Col1 int, Col2 int, Col3 int, Col4 int);
    INSERT INTO @MyTable VALUES
    (1, 10, 100, 7),
    (2, 20, 200, 2),
    (2, 20, 200, 1),
    (3, 30, 300, 3),
    (1, 10, 200, 4),
    (1, 10, 100, 5),
    (1, 10, 100, 6);
    WITH cte (RN, Col1, Col2, Col3, Col4)
    AS (SELECT ROW_NUMBER() OVER (PARTITION BY Col1, Col2, Col3 ORDER BY (SELECT 0)) AS RN, Col1, Col2, Col3, Col4
    FROM @MyTable)
    DELETE FROM cte
    OUTPUT DELETED.Col1, DELETED.Col2, DELETED.Col3, DELETED.Col4
    INTO @OutTable (Col1, Col2, Col3, Col4)
    WHERE RN > 1;
    SELECT * FROM @OutTable;
    And this is the result:
    The MS 139444 article Satish mentioned is focussed on duplicate PKs removal. Thanks for the hint.
    Thanks to you all for your rapid response.
    Regards Uwe

Maybe you are looking for