Help: SQL list all duplicate records

Given table B with employer_id, ssn, period and employee_name, list all records with duplicate ssn for a given period and employer_id.
I used:
select employer_id, ssn, employee_name, count(ssn) from B
group by employer_id, ssn
where period='xxx' and count(ssn)>1
got error:
ORA-00933: SQL command not properly ended
checked sometime and still can not figure it out, any help will be greatly appreciated.

select employer_id, ssn, employee_name, count(ssn) from B
where period='xxx'
group by employer_id, ssn,employee_name having count(ssn)>1
Regards
Helio Dias
http://heliodias.com

Similar Messages

  • Report to list all infotype record per employee

    Hi All
    is there a report that list all infotypes record per employee  ?
    thanks for helping
    Corinne

    Hi,
    It will not be feasible as all the IT has different fields.
    There is no standard report as Mr, Raghu mentioned.
    Ketul

  • How can I view all duplicate records

    Hello everyone,
    My question is very straight forward. How can I view all duplicate records?
    Thanks in advance,
    Sonya

    If you want to see duplicate records in a table and how many you have you can do something like this:
    Select all of the columns in the table and look for those having more than one row. If you're more concerned
    about duplicate keys than each column individual column being the same just select the key columns.
    select c1, c2, c3,..., count(*)
    from table
    group by c1, c2, c3...
    having count(*)>1
    order by c1, c2, c3...
    If you eventually want to get rid of the duplicates you can issue:
    delete from table t1
    where rowid not in
    (select max(rowid)
    from table t2
    where t1.c1 = t2.c1
    and t1.c2 = t2.c2...)
    Where c1, c2, c3... match your column list from the select statement above.
    HTH

  • Remove all duplicate records and load into temp table

    Hi
    I have a table contains data like this.
    Emp No Designation location
    1111 SE CA
    1111 DE CT
    3456 WE NJ
    4523 TY GH
    We found that there are two duplicate records for emp no: 1111. I want to delete all duplicate records (in this case two records for emp no:1111) and load into the temp table.
    Please advice me how to do it.

    Oh look, you can search the forums...
    http://forums.oracle.com/forums/search.jspa?threadID=&q=delete+duplicates&objID=f75&dateRange=all&userID=&numResults=30

  • Return all duplicate record

    hi how can i return all duplicate records, not just the records which is duplicate, can you check my query
    select c_code,facility_name,npo_registration_no,AGR.CONTRACT_NO
    ,ssch.name subsidy,SSCH.SUB_PROGRAMME, organisation,opex_allocation
    from sms_parties par
    ,sms_agreements agr
    ,SMS_SUBSIDY_SCHEMES_VW ssch
    ,sms_agreement_years ayea
    ,sms_agreement_status asta
    ,sms_fyea_open_vw fyea
    where par.id = agr.par_id
    and agr.id = ayea.id (+)
    and agr.contract_no like '%2011%'
    and ayea.asta_id = asta.id (+)
    and agr.ssch_id = SSCH.SSCH_ID
    and npo_registration_no in (
    select npo_registration_no
    from sms_parties
    group by npo_registration_no
    having count(*) > 1
    order by 1
    Edited by: user603350 on 2011/08/25 5:30 PM

    select *
    from (
      select c_code
            ,facility_name
            ,npo_registration_no
            ,AGR.CONTRACT_NO
            ,ssch.name subsidy
            ,SSCH.SUB_PROGRAMME
            ,organisation
            ,opex_allocation
            ,row_number() over ( partition by c_code
                                          ,facility_name
                                          ,npo_registration_no
                                          ,AGR.CONTRACT_NO
                                          ,ssch.name subsidy
                                          ,SSCH.SUB_PROGRAMME
                                          ,organisation
                                          ,opex_allocation
                                 order by npo_registration_no) rn
            ,count(1) over ( partition by c_code
                                          ,facility_name
                                          ,npo_registration_no
                                          ,AGR.CONTRACT_NO
                                          ,ssch.name subsidy
                                          ,SSCH.SUB_PROGRAMME
                                          ,organisation
                                          ,opex_allocation) cn
      from   sms_parties par
            ,sms_agreements agr
            ,SMS_SUBSIDY_SCHEMES_VW ssch
            ,sms_agreement_years ayea
            ,sms_agreement_status asta
            ,sms_fyea_open_vw fyea
      where  par.id             = agr.par_id
      and    agr.id             = ayea.id (+)
      and    agr.contract_no    like '%2011%'
      and    ayea.asta_id       = asta.id (+)
      and    agr.ssch_id = SSCH.SSCH_ID
    where rn != 1
    and   cn > 1
    order by 1or
    select *
    from (
      select c_code
            ,facility_name
            ,npo_registration_no
            ,AGR.CONTRACT_NO
            ,ssch.name subsidy
            ,SSCH.SUB_PROGRAMME
            ,organisation
            ,opex_allocation
            ,row_number() over ( partition by npo_registration_no
                                 order by npo_registration_no) rn
            ,count(1) over ( partition by npo_registration_no) cn
      from   sms_parties par
            ,sms_agreements agr
            ,SMS_SUBSIDY_SCHEMES_VW ssch
            ,sms_agreement_years ayea
            ,sms_agreement_status asta
            ,sms_fyea_open_vw fyea
      where  par.id             = agr.par_id
      and    agr.id             = ayea.id (+)
      and    agr.contract_no    like '%2011%'
      and    ayea.asta_id       = asta.id (+)
      and    agr.ssch_id = SSCH.SSCH_ID
    where rn != 1
    and   cn > 1
    order by 1Included both as I'm not sure about your logic, but you'll have to play around with the PARTITION BY window.
    UNETSTED!

  • SQL Loader loads duplicate records even when there is PK defined

    Hi,
    I have created table with pk on one of the column.Loaded the table using sql loader.the flat file has duplicate record.It loaded all the records without any error but now the index became unusable.
    The requirement is to fail the process if there are any duplicate.Please help me in understaing why this is happening.
    Below is the ctl file
    OPTIONS(DIRECT=TRUE, ERRORS=0)
    UNRECOVERABLE
    load data
    infile 'test.txt'
    into table abcdedfg
    replace
    fields terminated by ',' optionally enclosed by '"'
    col1 ,
    col2
    i defined pk on col1

    Check out..
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14215/ldr_modes.htm#sthref1457
    It states...
    During a direct path load, some integrity constraints are automatically disabled. Others are not. For a description of the constraints, see the information about maintaining data integrity in the Oracle Database Application Developer's Guide - Fundamentals.
    Enabled Constraints
    The constraints that remain in force are:
    NOT NULL
    UNIQUE
    PRIMARY KEY (unique-constraints on not-null columns)Since OP has the primary key in place before starting the DIRECT path load, this is contradictory to what the documentation says or probably a bug?

  • Help....Duplicate records found in loading customer attributes!!!!

    Hi ALL,
    we have a full update master data with attributes job that  is failed with this error message: (note the processing is PSA and then Data targets)
    1 duplicate record found. 66 recordings used in table /BIC/PZMKE_CUST RSDMD 199     
    1 duplicate record found. 0 recordings used in table /BIC/PZTSA_CUST RSDMD 199     
    1 duplicate record found. 0 recordings used in table /BIC/PZTSA_CUST RSDMD 199     
    1 duplicate record found. 0 recordings used in table /BIC/XZTSA_CUST RSDMD 199     
    1 duplicate record found. 66 recordings used in table /BIC/XZMKE_CUST RSDMD 199     
    our datasource is 0CUSTOMER_ATTR i tried to use the transaction rso2 to get more information about this datasource to know where i can find the original data in R/3 but when i execute i got this message:
    DataSource 0CUSTOMER_ATTR  is extracted using functional module MDEX_CUSTOMER_MD
    Can you help me please what should i do to correct and reload or to find the duplicate data to tell the person on R/3 system to delete the duplicate.
    Thanks
    Bilal

    Hi Bilal,
    Could you try the following pls.
    Only PSA and Update Subsequently into Datatargets in the Processing tab.
    In Update tab use Error Handling , mark "Valid Records Update, Reporting Possible(request green).
    If my assumptions are right, this should collect the duplicate records in another request, from where you could get the data that needs to be corrected.
    To resolve this issue, just load using ONLY PSA and Update Subsequently into Datatargets with Ignore duplicate Records checked.
    Cheers,
    Praveen.

  • Help with clean up duplicate records

    One of my tables have duplicate records in paris that needs to be cleaned up. I want to cleanup the earlier TIMESTAMP.
    ID MODIF_TIME_STAMP
    483070 1/7/2005 11:49
    483070 1/13/2005 17:19
    483071 1/6/2005 11:49
    483071 1/14/2005 17:19
    483072 1/15/2005 11:49
    483072 1/07/2005 17:19
    9000 records
    What is the easiest way to pick only the ID of the earlier timestamp of each pair.
    Thanks in advance.
    Ittichai

    Hallo,
    delete from your_tab
    where rowid in
    (select rowid from
    (select rowid, id, modif_time_stamp, row_number() over (partition by id order by modif_time_stamp desc) rn from your_tab)
    where rn > 1
    )This query deletes records with earlier date for every id
    Regards
    Dmytro
    Message was edited by:
    Dmytro Dekhtyaryuk

  • Help in Elimating the Duplicate records

    Hi all,
    Can anyone help me on this ..i am going to use this SQL in a FOR LOOP CURSOR
    This SQL is now Returning Multiple records for each participant because of the c.cmpnt_beg_dte
    because there are multiple begin dates for each participants but i want only single record for each
    participant with the oldest cmpnt_beg_dte
    SELECT
    distinct a.partc_ssn, a.partc_id, b.LOC_ID, e.loc_desc, c.CMPNT_BEG_DTE
    FROM etr_rgt_partc a,
    etr_fst_partc_rgst b,
    etr_fst_partc_cmpnt c,
    etr_smt_fst_cmpnt_mstr d,
    etr_smt_agy_loc_mstr e
    WHERE a.partc_id = b.partc_id
    AND b.partc_id = c.partc_id
    AND b.fs_rgst_id = c.fs_rgst_id
    AND c.cmpnt_nbr = d.cmpnt_nbr
    AND b.loc_id = e.loc_id
    AND B.LOC_ID = 'ES00205'
    AND a.partc_id = 2402514
    AND (c.cmpnt_beg_dte BETWEEN TO_DATE ('10/01/2007', 'MM/DD/YYYY')
    AND TO_DATE ('09/30/2008', 'MM/DD/YYYY'))
    This Query is giving me Result Like the below
    521140046,2402514,ES00205,205- TN Career Center - Savannah,11/8/2007
    521140046,2402514,ES00205,205- TN Career Center - Savannah,2/1/2008
    but i want only 1st record ... now i executed this query manually by passing PARTC_ID but
    i will pass this query inside my procedure ..if i limit by using order by and rownum=1
    for all participants it is giving only 1 row ..
    any one please help me in this issue ..
    To be on Short i want to elimate the Duplicates .. ..but based on Single Column Value
    Thanks in Advance ,
    Data Boy

    If SSN/partc_id and loc_id are always the same for each record (and seems like they should be), then:
    SELECT
    a.partc_ssn, a.partc_id, b.LOC_ID, e.loc_desc, MIN(c.CMPNT_BEG_DTE)
    FROM etr_rgt_partc a,
    etr_fst_partc_rgst b,
    etr_fst_partc_cmpnt c,
    etr_smt_fst_cmpnt_mstr d,
    etr_smt_agy_loc_mstr e
    WHERE a.partc_id = b.partc_id
    AND b.partc_id = c.partc_id
    AND b.fs_rgst_id = c.fs_rgst_id
    AND c.cmpnt_nbr = d.cmpnt_nbr
    AND b.loc_id = e.loc_id
    AND B.LOC_ID = 'ES00205'
    AND a.partc_id = 2402514
    AND (c.cmpnt_beg_dte BETWEEN TO_DATE ('10/01/2007', 'MM/DD/YYYY')
    AND TO_DATE ('09/30/2008', 'MM/DD/YYYY'))
    GROUP BY a.partc_ssn, a.partc_id, b.LOC_ID, e.loc_desc

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

  • 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

  • Remove Duplicate record

    Dear All,
    I have oracle 10g R2 On windows.
    I have table structure like below...
    ASSIGNED_TO
    USER_ZONE
    CREATED
    MASTER_FOLIO_NUMBER
    NAME
    A_B_BROKER_CODE
    INTERACTION_ID
    INTERACTION_CREATED
    INTERACTION_STATE
    USER_TEAM_BRANCH
    A4_IN_CALL_TYPE
    A5_IN_CALL_SUBTYPE
    DNT_AGING_IN_DAYS
    DNT_PENDING_WITH
    DNT_ESCALATION_STAGE_2
    DT_UPDATEI use sql loader to load the data from .csv file to oracle table and have assign the value to dt_update sysdate. Everytime i execute the sql loader control file dt_update set as sysdate.
    Sometimes problem occures while inserting data through sql loader and half row get insert. after solving the problem again i execute sql loader and hence these duplicate records get inserted.
    Now I want to remove all the duplicate records for those dt_update is same.
    Please help me to solve the problem
    Regards,
    Chanchal Wankhade.

    Galbarad wrote:
    Hi
    I think you have two ways
    first - if it is first import in your table - you can delete all record from table and run import yet one time
    second - you can delete all duplicate records and not running import
    try this script
    <pre>
    delete from YOUR_TABLE
    where rowid in (select min(rowid)
    from YOUR_TABLE
    group by ASSIGNED_TO,
    USER_ZONE,
    CREATED,
    MASTER_FOLIO_NUMBER,
    NAME,
    A_B_BROKER_CODE,
    INTERACTION_ID,
    INTERACTION_CREATED,
    INTERACTION_STATE,
    USER_TEAM_BRANCH,
    A4_IN_CALL_TYPE,
    A5_IN_CALL_SUBTYPE,
    DNT_AGING_IN_DAYS,
    DNT_PENDING_WITH,
    DNT_ESCALATION_STAGE_2,
    DT_UPDATE)
    </pre>Have you ever tried that script for deleting duplicates? I think not. If you did you'd find it deleted non-duplicates too. You'd also find that it only deletes the first duplicate where there are duplicates.
    XXXX> CREATE TABLE dt_test_dup
      2  AS
      3  SELECT
      4      mod(rownum,3) id
      5  FROM
      6      dual
      7  CONNECT BY
      8      level <= 9
      9  UNION ALL
    10  SELECT
    11      rownum + 3 id
    12  FROM
    13      dual
    14  CONNECT BY
    15      level <= 3
    16  /
    Table created.
    Elapsed: 00:00:00.10
    XXXX> select * from dt_test_dup;
            ID
             1
             2
             0
             1
             2
             0
             1
             2
             0
             4
             5
             6
    12 rows selected.
    Elapsed: 00:00:00.18
    XXXX> delete
      2  from
      3      dt_test_dup
      4  where
      5      rowid IN ( SELECT
      6                    MIN(rowid)
      7                 FROM
      8                     dt_test_dup
      9                 GROUP BY
    10                     id
    11                )
    12  /
    6 rows deleted.
    Elapsed: 00:00:00.51
    XXXX> select * from dt_test_dup;
            ID
             1
             2
             0
             1
             2
             0
    6 rows selected.
    Elapsed: 00:00:00.00

  • Duplicate records in PSA

    Hi all,
    how to identify & eliminate the duplicate records in the PSA??

    Hi,
    Here is the FI Help for the 'Handle Duplicate Record Keys' option in the Update tab:
    "Indicator: Handling Duplicate Data Records
    If this indicator is set, duplicate data records are handled during an update in the order in which they occur in a data package.
    For time-independent attributes of a characteristic, the last data record with the corresponding key within a data package defines the the valid attribute value for the update for a given data record key.
    For time-dependent attributes, the validity ranges of the data record values are calculated according to their order (see example).
    If during your data quality measures you want to make sure that the data packages delivered by the DTP are not modified by the master data update, you must not set this indicator!
    Use:
    Note that for time-dependent master data, the semantic key of the DTP may not contain the field of the data source containing the DATETO information. When you set this indicator, error handling must be activated for the DTP because correcting duplicate data records is an error correction. The error correction must be "Update valid records, no reporting" or "Update valid records, reporting possible".
    Example:
    Handling of time-dependent data records
    - Data record 1 is valid from 01.01.2006 to 31.12.2006
    - Data record 2 has the same key but is valid from 01.07.2006 to 31.12.2007
    - The system corrects the time interval for data record 1 to 01.01.2006 to 30.06.2006. As of 01.07.2006, the next data record in the data package (data record 2) is valid."
    By flagging this option in the DTP, you are allowing it to take the latest value.
    There is further information at this SAP Help Portal link:
    http://help.sap.com/saphelp_nw04s/helpdata/en/d0/538f3b294a7f2de10000000a11402f/content.htm
    Rgds,
    Colum

  • Identify Duplicate Records

    Post Author: chrise
    CA Forum: Crystal Reports
    I know that Crystal has the ability to identify all distinct records, thereby, getting rid of all duplicate records. However, I need to do the exact opposite and so far have been unsuccessful. Can anyone aid me in creating a report to identify only duplicate records in Crystal?
    Thanks.

    Post Author: SKodidine
    CA Forum: Crystal Reports
    Check out this KBase article.
    Retrieving duplicate records

  • How can I view duplicate records in a table?

    Hello everyone,
    My question is very straight forward. How can I view all duplicate records?
    Thanks in advance,
    Sonya

    Easy enough,
    select t1.n1,t1.c1,count(*) as "TOTAL_DUPS" from tableA t1 having count(*) > 1 group by t1.n1,t1.c1 order by count(*) desc
    Tyler

Maybe you are looking for

  • Not able to fetch the data by Virtual Cube

    Hi Experts, My requirement is I need to fetch the data from Source System (From Data base table) by using Virtual Cube. What I have done is I have created Virtual Cube and created corresponding Function Module in Source System. That Function MOdule i

  • Spotlight does not stop indexing

    I need help: Just started the brand new MacPro 2x 2.66. The long desired spotlight (I run osx 1.3.9 before) does not work. Spotlight never stop to index. It runs and runs. If I add the hard drive to privacy in the system preferences it stops, but as

  • Firefox will be working perfectly, but after a period of time, and sometimes after a period of inactivity, the browser just hangs.

    Mouse clicks to hyperlinks instigate an error noise, and to recover your internet session, all you can do is re-start the PC - but also re-setting the router seems to clear the problem. Its not the individual PC, as my netbook which i connect through

  • Default values for confirmation control key

    Dear forum I am using a confirmation control key 0004 Shipping notification (standard SAP) in the Purchase order line item (created with ME21n). When I enter the confirmation data (with transaction ME22n) in the purchase order line item (confirmation

  • Profile for LRE

    Hi, I am using 2900 LRE. Now I want to create a profile for 64K transfer rate for each port. I am creating a profile but It's not working. Please help me to create this profile. Thanks, Mustafa