How can we select duplicate records from a table

Hi
I desire to use a query to select duplicate columns (based on all the columns of the table) ...
I am able to write queries which include column names, but when my table contains more than 50 columns, is it advisable for me to mention all the 50 column names in the query or is there any other query by which duplicate rows can be selected without column names being mentioned ?
Thnx in advance
Regards

Basic rule of relational design says that "thy table shalt have a primary key".
Now assuming that you do not have a primary key constraint and that resulted in duplicates, you should still have a couple of columns that uniquely describes a row in that table.
To select duplicate rows can then be done by joining rows with the primary key (same set of unique columns), where rows have different rowids (physical addresses).
E.g.
select
t1.*,
t2.*
from table t1,
table t2
where t1.col1 = t2.col1
and t1.col2 = t2.col2
and t1.rowid < t2.rowidIf you do not have a couple of columns (primary key) that uniquely identifies a row, then you do not have duplicates in the table - as there cannot be duplicates without having a means of unique identification.

Similar Messages

  • How can I select random records from one column

    How can I random select 400 records from a column contains more than 500,000 records? And how long will it take in oracle? Thanks.

    here is one option: (just change 5 to suit your needs...)
    SQL>select * from (
      2  select object_name
      3  from all_objects
      4  order by dbms_random.random
      5  ) where rownum < 5
      6  /
    OBJECT_NAME
    UTL_SYS_COMPRESS
    GV_$LOG_HISTORY
    GV_$LOGMNR_LOGS
    WWV_FLOW_THEME_7
    SQL>/
    OBJECT_NAME
    WWV_FLOW_UPGRADE_REPORT
    WRI$_ADV_SQLT_STATISTICS_PK
    V_$DATABASE
    GV_$SERVICEMETRIC
    SQL>/
    OBJECT_NAME
    WWV_FLOW_CREATE_FLOW_API
    WRH$_SERVICE_WAIT_CLASS_BL
    EXU8SNAPL
    GV$SERVICEMETRIC_HISTORY
    SQL>                well, regarding how long will it take... it depends from lots of variables...
    Cheers,
    Andrea

  • 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

  • How can I select several emails from 3900 on my 5c and delete the rest easily

         How can I select several emails from 3900 on my 5c and delete the rest easily

    We'll I don't think there's a easy way to delete a lot of emails besides deleting all of them. To delete all of them click on inbox them edit then "mark all" then trash/delete. Other than that you will have to specifically deleted the ones you want to delete.

  • How can  distribute 5 lakhs records from sap R/3 setup tables ?

    How can  distribute 5 lakhs records from sap R/3 setup tables in to multiple  requests in sap BI?

    Hello,
    what is "lakhs" ?
    Please use plain English words on a world wide forum...
    Regards,
    Olivier

  • How to delete the duplicate data  from PSA Table

    Dear All,
    How to delete the duplicate data  from PSA Table, I have the purchase cube and I am getting the data from Item data source.
    In PSA table, I found the some cancellation records for that particular records quantity  would be negative for the same record value would be positive.
    Due to this reason the quantity is updated to target but the values would summarized and got  the summarized value  of all normal and cancellation .
    Please let me know the solution how to delete the data while updating to the target.
    Thanks
    Regards,
    Sai

    Hi,
    in deleting the records in PSA table difficult and how many you will the delete.
    you can achieve the different ways.
    1. creating the DSO maintain the some key fields it will overwrite the based on key fields.
    2. you can write the ABAP logic deleting the duplicate records at info package level check with the your ABAPer.
    3.you can restrict the cancellation records at query level.
    Thanks,
    Phani.

  • How can we delete a line from the table control .

    hi all
    how can we delete a line from the table control .
    situation is.
    created table control in se51 which will display the data of a table.
    how could i select a line from the table control ?
    how could i delete the selected lines form the table.
    thanks in advance

    Change the Table Control attributes such that user can only select a single record(row).
    <u>Tip to delete a selected record</u>
    1) write a module 'Mark' in the PAI as below
    PROCESS AFTER INPUT.
    MODULE cancel AT EXIT-COMMAND.
    LOOP WITH CONTROL table_view.
    MODULE read_table_control.
    FIELD flag MODULE mark ON INPUT.
    ENDLOOP.
    MODULE user_command_0100.
    2) Module Mark is below.
    MODULE mark INPUT.
    CHECK flag = 'X'.
    x = table_view-top_line + sy-stepl - 1.
    Delete itab INDEX x.
    ENDMODULE. " mark INPUT
    Table_view is the TableControl Name.
    'flag' is of type char(1) available in the Internal table which was assigned to the select option in the table control.
    <u>award if uesful</u>
    Regards,
    Sudheer

  • How to delete the duplicate records in a table without promary key

    I have a table that contains around 1 million records and there is no promary key or auto number coulums. I need to delete the duplicate records from this table. what is the simple effective way to do this.

    Please see this link:
    Remove duplicate records ...
    sqldevelop.wordpress.com

  • How can i convert the data from mutiple-table to the other database(MSSQL)?

    Dears,
    How can i convert the data from mutiple-table to the other database such as MS-SQL?
    I have a third party system based on MS-SQL 2000.
    Now we want to make a integration between SAP R/3(Oracle) and SQL server.
    When my user releases the purchase order in R/3, the application we coded will convert the releated data to the temp database on the SQL server.
    But i don't know which tools will help me reach the purpose.  BAPI, LSMW, IDoc... ???
    Would anybody tell me which way is better and how to do?
    Thanks a lot!
    Kevin Wang

    Hello Kevin,
    The question to use which method depend on your detail requirements. If you use BAPI, you need to find which Bapi can provide the data you want. Bapi normally use as a function called by external system. So you need to develop an external program like VB/Java to call this Bapi and move it to SQL. LSMW is use when you want to upload data from an external system to SAP. So it does not serve your requirement. Idoc can be use to export data to an external system. Again like Bapi, you need to find what Idoc can provide the data you want. However, it does not any programming from the external system. If I were you, based on your requirements, I think writing an Abap program that read the data you want and download it to NT/SQL server will be faster and easier.

  • Importing and Updating Non-Duplicate Records from 2 Tables

    I need some help with the code to import data from one table
    into another if it is not a duplicate or if a record has changed.
    I have 2 tables, Members and NetNews. I want to check NetNews
    and import non-duplicate records from Members into NetNews and
    update an email address in NetNews if it has changed in Members. I
    figured it could be as simple as checking Members.MembersNumber and
    Members.Email against the existance of NetNews.Email and
    Members.MemberNumber and if a record in NetNews does not exist,
    create it and if the email address in Members.email has changed,
    update it in NetNews.Email.
    Here is what I have from all of the suggestions received from
    another category last year. It is not complete, but I am stuck on
    the solution. Can someone please help me get this code working?
    Thanks!
    <cfquery datasource="#application.dsrepl#"
    name="qryMember">
    SELECT distinct Email,FirstName,LastName,MemberNumber
    FROM members
    WHERE memberstanding <= 2 AND email IS NOT NULL AND email
    <> ' '
    </cfquery>
    <cfquery datasource="#application.ds#"
    name="newsMember">
    SELECT distinct MemberNumber
    FROM NetNews
    </cfquery>
    <cfif
    not(listfindnocase(valuelist(newsMember.MemberNumber),qryMember.MemberNumber)
    AND isnumeric(qryMember.MemberNumber))>
    insert into NetNews (Email_address, First_Name, Last_Name,
    MemberNumber)
    values ('#trim(qryMember.Email)#',
    '#trim(qryMember.FirstName)#', '#trim(qryMember.LastName)#', '#
    trim(qryMember.MemberNumber)#')-
    </cfif>
    </cfloop>
    </cfquery>
    ------------------

    Dan,
    My DBA doesn't have the experience to help with a VIEW. Did I
    mention that these are 2 separate databases on different servers?
    This project is over a year old now and it really needs to get
    finished so I thought the import would be the easiest way to go.
    Thanks to your help, it is almost working.
    I added some additional code to check for a changed email
    address and update the NetNews database. It runs without error, but
    I don't have a way to test it right now. Can you please look at the
    code and see if it looks OK?
    I am also still getting an error on line 10 after the routine
    runs. The line that has this code: "and membernumber not in
    (<cfqueryparam list="yes"
    value="#valuelist(newsmember.membernumber)#
    cfsqltype="cf_sql_integer">)" even with the cfif that Phil
    suggested.
    <cfquery datasource="#application.ds#"
    name="newsMember">
    SELECT distinct MemberNumber, Email_Address
    FROM NetNewsTest
    </cfquery>
    <cfquery datasource="#application.dsrepl#"
    name="qryMember">
    SELECT distinct Email,FirstName,LastName,MemberNumber
    FROM members
    WHERE memberstanding <= 2 AND email IS NOT NULL AND email
    <> ' '
    and membernumber not in (<cfqueryparam list="yes"
    value="#valuelist(newsmember.membernumber)#"
    cfsqltype="cf_sql_integer">)
    </cfquery>
    <CFIF qryMember.recordcount NEQ 0>
    <cfloop query ="qryMember">
    <cfquery datasource="#application.ds#"
    name="newsMember">
    insert into NetNewsTest (Email_address, First_Name,
    Last_Name, MemberNumber)
    values ('#trim(qryMember.Email)#',
    '#trim(qryMember.FirstName)#', '#trim(qryMember.LastName)#', '#
    trim(qryMember.MemberNumber)#')
    </cfquery>
    </cfloop>
    </cfif>
    <cfquery datasource="#application.dsrepl#"
    name="qryEmail">
    SELECT distinct Email
    FROM members
    WHERE memberstanding <= 2 AND email IS NOT NULL AND email
    <> ' '
    and qryMember.email NEQ newsMember.email
    </cfquery>
    <CFIF qryEmail.recordcount NEQ 0>
    <cfloop query ="qryEmail">
    <cfquery datasource="#application.ds#"
    name="newsMember">
    update NetNewsTest (Email_address)
    values ('#trim(qryMember.Email)#')
    where email_address = #qryEmail.email#
    </cfquery>
    </cfloop>
    </cfif>
    Thank you again for the help.

  • QUERY - No Duplicate records from 2nd table ???

    Hi Experts,
    I really need help with this. I have 2 tables A and B. See below
    <b>A -
         B</b>
    X -
         XB1
    XB2
    XB3
    Y----
    YB
    Z----
    ZB
    I select a record from A and get its record from B and give it on the output. For entry X I have 3 records in Table B. I want the output to give only 1 record from B for X. It can be any record. How can this be achieved in Query ?
    Is there a special Join ? or can this be achieved by coding in Query ? If so how ?
    I really appreciate your help.
    Thanks !!

    First get the data from table A.
    select * from table (A) into table i_a.
    loop at i_a.
    select single * from table B into table i_b.
    move b reord to final internal table
    append final internal table.
    endloop.

  • How to delete some of records from wf_notifications table any API Name?

    Hi All,
    I want to delete some of records from wf_notifications table , can any one tell API' name and Back end delete process.
    Thanks,
    Ramu
    Edited by: Ramu on Mar 20, 2013 5:42 AM

    Hi ,
    I hv done below script, now it's working fine.
    DECLARE
    CURSOR csr_transaction_id IS
    SELECT   hat.transaction_id,
             hat.item_type,
             hat.item_key,
             ppx.employee_number,
             hat.section_display_name
      FROM   hr_api_transactions hat, per_people_x ppx
    WHERE   hat.process_name = 'HR_PERSONAL_INFO_JSP_PRC'
             AND hat.selected_person_id = ppx.person_id
             AND ppx.employee_number IN
                      ('100024773',
                       '100024820',
                       '100024859',
                       '100024879',
                       '100024902',
                       '100024937',
                       '100025137',
                       '100026470',
                       '610014755',
                       '610017039')
    order by  ppx.employee_number;
    BEGIN
      dbms_output.put_line('***Deleted all Transactions  and Notifications of below Employee Personals Tranactions ***');
       FOR my_cur_v IN csr_transaction_id
       LOOP
       /*Delete all Transaction_id's in hr_api_transactions,hr_api_transaction_steps,hr_api_transaction_values and hr_api_transaction_steps_bk tables */
        hr_transaction_swi.delete_transaction
                              p_transaction_id =>my_cur_v.transaction_id,
                              p_validate => hr_api.g_false_num
        wf_engine.abortprocess  (
                                  itemtype => my_cur_v.item_type,
                                 itemkey => my_cur_v.item_key
         /* Deleted all Notification_id's and item_key's in wf_item_activity_statuses,wf_items,wf_item_attribute_values,wf_notifications     Table */                     
         wf_purge.items (
                          itemtype => my_cur_v.item_type,
                         itemkey => my_cur_v.item_key
        dbms_output.put_line('Emp No --'||my_cur_v.employee_number||'Transaction_id :'||my_cur_v.transaction_id||'Emp Personal Info :'||my_cur_v.section_display_name||
                              'Item Type :'||my_cur_v.item_type|| 'Item Key :'||my_cur_v.item_key); 
       END LOOP;
       commit;
    EXCEPTION
    WHEN OTHERS THEN
      dbms_output.put_line('hr_transaction_swi.delete_transaction api goest to exception block'    ||sqlcode|| '  '||sqlerrm);
    END;  
    /thanks,
    Ramu

  • How can we extract unique materials from cluster tables

    I want to get unique materials from CDPOS table( which is a cluster table) when i use SELECT distinct its giving me syntax error

    Hi,
    I don't think you can use select distict for material in table CDPOS (cluster table). You can only use distinct * or count ( * ) aggregation function.
    Regards,
    Ferry Lianto

  • To delete duplicate records from internal table

    hi friends,
    i have to delete records from internal table based on following criterion.
    total fields are 7.
    out of which  if 4 fields are same and 5th field is different,then both records must be deleted.
    in case all five fields are same,the program should do nothing.
    for example.
    if there are 3 records as follows
    a1 b1 c1 d1 e1 f g
    a1 b1 c1 d1 e2 w r
    a1 b1 c1 d1 e1 j l
    then first two records should be deleted as four fields are same but fifth(e) field differs.
    but third record should remain as it is evenif first five fields are same for first and third record.
    values of last two fields need not to be consider for deleting the records.

    LOOP AT ITAB.
      V_FILED5 = ITAB-F5. "to compare later
      V_TABIX = SY-TABIX. "used to delete if condition not matches
      READ TABLE ITAB WITH KEY F1 = ITAB-F1
                               F2 = ITAB-F2
                               F3 = ITAB-F3
                               F4 = ITAB-F4.
      IF SY-SUBRC = 0.
        IF ITAB-F5 <> V_FIELD5.
    *--both the records to be deleted,as Field5 is different.
          DELETE ITAB INDEX SY-TABIX. "deletes that record
          DELETE ITAB INDEX V_TABIX. "deletes the current record
        ENDIF.
      ENDIF.
    ENDLOOP.
    Message was edited by: Srikanth Kidambi
    added comments
    Message was edited by: Srikanth Kidambi

  • How can i select the rows from the 3 tables by particular column name?

    Vehicle Passing Summary table structure
              PsngSmry_ID(Number),Vehicle_iD(Number),PsngSmryTime(datetime)
    Vehicle table structure
              Vehicle_iD(Number),VehicleName(VarChar2),VehicleType(VarChar2)
    Here Vehicle_iD is the Primary Key
    Equipment Table Structure
              Eqpmt_id(Number),Vehicle_iD(Number),EqpmtName(VarChar2),EqpmtType(VarChar2)
    Here Eqpmt_id is the Primary Key and Vehicle_iD is the foreign Key
    Equipment Component Table Structure
              Eqpmt_Cmpnt_id(Number) ,Eqpmt_id(Number),EqpmtCmpntName(VarChar2),EqpmtCmpntName(VarChar2),Parent_Eqpmnt_ID(Number)
    Here Eqpmt_Cmpnt_id is the Primary Key and Eqpmt_id is the foreign Key
    The rows in the Vehicle Passing Summary table
         PsngSmry_ID Vehicle_ID     PsngSmryTime
         111111          80986246     2010/10/11
         111112          80986247     2010/10/12
         111113          80986248     2010/10/10
    The rows in the Vehicle Table
         Vehicle_iD     VehicleName     VehicleType
         80986246          Lorry          Four Wheeler
         80986247          Van          Four Wheeler
         80986248          Bus          Four Wheeler
    The rows in the Equipment Table:
         Eqpmt_id     Vehicle_iD     EqpmtName          EqpmtType
         109846          80986246          2 Axle Lorry          CAR
    109821          80986246          4 Axle Lorry          CAR
    109825          80986246          4 Axle Lorry          CAR
         109562          80986247          2 Axle VAn          CAR
    109555          80986247          3 Axle VAn          CAR
    109777          80986247          3 Axle VAn          CAR
         109587          80986248          2 Axle Bus          CAR
    The rows in the Equipment Component Table :
         Eqpmt_Cmpnt_id Eqpmt_id EqpmtCmpntName Parent_Eqpmnt_ID
         20904146          109846          Truck               
         20904147          109846          Truck
         20904148          109846          Axle               20904146
         20904159          109846          Axle               20904146
         20904167          109846          Wheel               20904148
         20904177          109846          Wheel               20904148
         20904185          109846          Wheel               20904159
         20904325          109846          Wheel               20904159
         20904188          109846          Axle               20904147
         20904189          109846          Axle               20904147
         20904195          109846          Wheel               20904188
         20904196          109846          Wheel               20904188
         20904197          109846          Wheel               20904189
         20904398          109846          Wheel               20904189
         10904146          109562          Truck               
         10904147          109562          Truck
         10904148          109562          Axle               10904146
         10904159          109562          Axle               10904146
         10904167          109562          Wheel               10904148
         10904177          109562          Wheel               10904148
         10904185          109562          Wheel               10904159
         10904325          109562          Wheel               10904159
         10904188          109562          Axle               10904147
         10904189          109562          Axle               10904147
         10904195          109562          Wheel               10904188
         10904196          109562          Wheel               10904188
         10904197          109562          Wheel               10904189
         10904398          109562          Wheel               10904189
    Note : In Equipment Component Table,the hierarchy will be Truck-->Axle-->Wheel.So
    1.the Parent_Eqpmnt_ID of Axle is Truck's Eqpmt_Cmpnt_id.
    2.the Parent_Eqpmnt_ID of Wheel is Axle's Eqpmt_Cmpnt_id.
    Now I want to write the store procedure which will take "PsngSmry_ID(Number)" as input and the o/p will be in the format :
         Eqpmt_Cmpnt_id Eqpmt_id EqpmtCmpntName Parent_Eqpmnt_ID
         20904146          109846      Truck     
         20904148          109846      Axle               20904146
         20904167          109846      Wheel               20904148
         20904177          109846      Wheel               20904148     
         20904159          109846      Axle               20904146
         20904185          109846      Wheel               20904159
         20904325          109846      Wheel               20904159
         20904147          109846      Truck
         20904188          109846      Axle               20904147
         20904195          109846      Wheel               20904188
         20904196          109846      Wheel               20904188
         20904189          109846      Axle               20904147
         20904197          109846      Wheel               20904189
         20904398          109846      Wheel               20904189
         10904146          109562          Truck     
         10904148          109562          Axle               10904146
         10904167          109562          Wheel               10904148
         10904177          109562          Wheel               10904148     
         10904159          109562          Axle               10904146
         10904185          109562          Wheel               10904159
         10904325          109562          Wheel               10904159
         10904147          109562      Truck
         10904188          109562      Axle               10904147
         10904195          109562      Wheel               10904188
         10904196          109562      Wheel               10904188
         10904189          109562      Axle               10904147
         10904197          109562      Wheel               10904189
         10904398          109562      Wheel               10904189
    **Please add these columns in the o/p **
    1.EqpmtName and EqpmtType from Eqpmt table
    2.VehicleName and Vehicle Type from Vehicle table
    3.PsngSmryTime from PassingSummary table **
    Can anyone tell me the solution?
    Edited by: 865216 on Jun 22, 2011 2:14 AM

    Hi,
    I am new to this technology;But, just wanted to help you.
    Please refer the code it might be atleast helpful for you.
    But am facing PL/SQL: ORA-00933: error and unable to resolve it.could anyone please correct this code.
    sorry if my code is totally wrong.
    Thank you,
    Rupa
    create or replace procedure Equipment_proc
    is
    begin
    DECLARE
    TYPE EQP_record IS RECORD (
    Vehicle_iD Vehicle.Vehicle_iD%TYPE,
    Eqpmt_Cmpnt_id Equipment_Component.Eqpmt_Cmpnt_id%type,
    EqpmtCmpntName Equipment_Component.EqpmtCmpntName%type,
    Parent_Eqpmnt_ID Equipment_Component.Parent_Eqpmnt_ID%type,
    Eqpmt_id Equipment.Eqpmt_id%type,
    vehicleId NUMBER);
    EQP_rec EQP_record;
    CURSOR EQP_cursor IS
    select a.Vehicle_iD,c.Eqpmt_Cmpnt_id,b.Eqpmt_id,c.EqpmtCmpntName,c.Parent_Eqpmnt_ID
    from Vehicle a,Equipment b,Equipment_Component c
    where a.Vehicle_iD=b.Vehicle_iD
    and b.Eqpmt_id=c.Eqpmt_id
    and a.vehicle_id=&EQP_rec.vehicleId;
    BEGIN
    OPEN EQP_cursor;
         FETCH EQP_cursor INTO EQP_rec;
         dbms_output.put_line(EQP_rec.Vehicle_iD,EQP_rec.Eqpmt_Cmpnt_id||','||EQP_rec.Eqpmt_id||','||EQP_rec.EqpmtCmpntName||','||EQP_rec.Parent_Eqpmnt_ID);
    CLOSE EQP_cursor;
    END;
    END;

Maybe you are looking for

  • Screen Saver "The selected folder contains no pictures"

    Hello, I recently had my HD replaced on my IBook after thermal damage took out the old one, and the good Apple Store folks recovered and replaces the date from the old fwinky drive. However, tweaking the configuration back into place, I noticed that

  • Windows 8.1 Task Sequence and Assigned Access

    Hi all, I have to build a few hundred kiosk machines with Windows 8.1, a custom LoB appx app, and assigned access. I am attempting to do it using SCCM OSD, but I have a couple of problems. Appx applications cannot be installed during a task sequence,

  • Billing docs are 2x posted to accounting

    Dear all, I am currently struggling with the following problem - would be great if somebody could help me with ideas about the root cause: VBRK-RFBSK -- 'Posting status' Accounting relevance of export billing docs was set to D -- 'not relevant' due t

  • Firefox causes entire Windows 7 x64 PC to Hang

    PC hangs for about 2 to 3 minutes and comes back. Everytime it hangs I get the following System Event: "The Windows Error Reporting Service service entered the running state". And when the system runs again it gives the same message but says "The Win

  • Custom color for navigation bar

    I am struggling to find a way to make my navigation bar color different that supported colors. SDK supports default style i.e. blue, black and black opaque. I know it is possible cause there so many apps doing so. For example midomi. I have searched