To find duplicate row

hello friends
i am having a table say tableA with 50 coloumns(col1.....col50) and large number of rows.
i want to find rows which are exactly same except last coloumn say col50.
the table dont have any primary key.
i can write like
SELECT          COUNT(1) COUNT,
                col1,col2,col3.....col49
FROM      tableA
GROUP BY col1,col2,col3.....col49       
ORDER BY        COUNT DESC
or like self join
but i need the time to execute query minimum .
please provide the solution for the same

If you want to select COL50 as well in the select list then you need to use analytical function. Something like this
select *
  from (
        select count(*) over(partition by col1, col2, ... col49) cnt
             , col1
             , col2
             , col49
             , col50
          from tableA
where cnt > 1;

Similar Messages

  • How to find duplicate row in sql query?

    Hi All,
    Please solve my query, find duplicate row and how to count its. your suggestion would be greatly appreciated.

    You can use group by and having.
    SQL> WITH t
      2       AS (SELECT       LEVEL id
      3                 FROM   DUAL
      4           CONNECT BY   LEVEL <= 5
      5           UNION ALL
      6           SELECT       LEVEL + 2
      7                 FROM   DUAL
      8           CONNECT BY   LEVEL <= 3)
      9  SELECT   *
    10    FROM   t;
            ID
             1
             2
             3
             4
             5
             3
             4
             5
    8 rows selected.
    SQL> WITH t
      2       AS (SELECT       LEVEL id
      3                 FROM   DUAL
      4           CONNECT BY   LEVEL <= 5
      5           UNION ALL
      6           SELECT       LEVEL + 2
      7                 FROM   DUAL
      8           CONNECT BY   LEVEL <= 3)
      9  SELECT     id, COUNT (*)
    10      FROM   t
    11  GROUP BY   id
    12    HAVING   COUNT (*) > 1;
            ID   COUNT(*)
             3          2
             4          2
             5          2
    SQL>

  • Find Duplicate Rows

    Hi,
    I have to find duplicate rows from a view where 2 columns of the view should be duplicate but the 3 col value should not be same.
    Pls help it's urgent.
    Thanks
    Regards
    Prashant

    Try this
    with t
    as
    select 1 rno, 'AAA' c1, 1 c2, 'NAME1' c3 from dual union all
    select 2, 'AAA', 1, 'NAME1' from dual union all
    select 3, 'AAA', 1, 'NAME3' from dual union all
    select 4, 'BBB', 2, 'NAME4' from dual union all
    select 5, 'BBB', 2, 'NAME4' from dual union all
    select 6, 'BBB', 2, 'NAME5' from dual
    select rno, c1, c2, c3
      from (
             select t.*, row_number() over(partition by c1, c2, c3 order by rno) rno1
               from t
    where rno1 = 1

  • How can i find Duplicate Rows in forms6i

    Hi,
    How can i find duplicate rows in multiple record in forms6i.
    Thanks
    Raghu.K

    Oops, sorry for misreading your question. (However the SQL I gave you above is also very handy, and worth saving.)
    Okay, this is off the top of my head and untested, but might just work. Assuming that your data block name is MYBLOCK, and that the item that you want to check for dups on is named MYNUM, create an item-level WHEN-VALIDATE-ITEM trigger with the following code.
    declare
    l_newest_record number(10) := :system.cursor_record;
    l_newest_mynum number(10) := :myblock.mynum;
    l_dup_found boolean := false;
    begin
    -- In this loop, we skip backwards through all new records to look for dups.
    while :system.cursor_record > 1 loop
    previous_record;
    if :system.record_status = 'NEW' then
    if :myblock.mynum := l_newest_mynum then
    l_dup_found := true;
    exit; -- Dup found!
    end if;
    else
    exit; -- We've gone backwards past the first new record.
    end if;
    end loop;
    -- In this loop, we return to the current record.
    while :system.cursor_record < l_newest_record loop
    next_record;
    end loop;
    if l_dup_found then
    raise duplicate_row_found; -- user-defined exception
    end if;
    end;
    The above code only checks for dups in the new form records. It assumes that a unique constraint in the database will deal with records actually committed.
    Armand

  • How can i find duplicate rows in a field of a table

    hi all,
    how can i able to find duplicate values in a field of a table????
    Regards

    test@ORA92>
    test@ORA92> with x as (
      2    select 1 as p, 'a' as q from dual union all
      3    select 1 as p, 'b' as q from dual union all
      4    select 2 as p, 'c' as q from dual union all
      5    select 3 as p, 'd' as q from dual union all
      6    select 3 as p, 'e' as q from dual union all
      7    select 3 as p, 'd' as q from dual
      8  )
      9  select p, q,
    10  case row_number() over (partition by p order by q)
    11    when 1 then null
    12    else 'Duplicate value: '||p||' of column p'
    13  end as msg
    14  from x;
             P Q MSG
             1 a
             1 b Duplicate value: 1 of column p
             2 c
             3 d
             3 d Duplicate value: 3 of column p
             3 e Duplicate value: 3 of column p
    6 rows selected.
    test@ORA92>
    test@ORA92>
    test@ORA92>cheers,
    pratz

  • How to update duplicate row from table

    Hi,
    how to update duplicate row from table?
    First to find duplicate row then update duplicate row with no to that duplicate row in oracle.
    can you give me suggestion on it?
    Thanks in advance.
    your early response is appreciated...

    In order to find a duplicate row, see:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1224636375004
    (or search this forum, your question has been asked before)
    In order to update it, just create and use an Oracle sequence, have it start and increment at a value that doesn't exist in your table.
    If that doesn't get you going, post some CREATE TABLE + INSERT INTO statements, and the results you want from them, in other words: a complete testcase.

  • Duplicate rows from table

    i have a table A suppose it has 3 columns
    id name sal
    ==========
    1 A 100
    1 A 100
    2 B 200
    2 B 200
    2 B 200
    3 C 300
    I want to find duplicate rows from the above table without passing any column in to the where clause .
    please help me to find out this query.

    maybe you should try the database forum...

  • Find out duplicate rows in a flat file before using sqlldr

    Hello i want to import via sqlldr from a flat file to a table inside my data base. My flat file has unfortunately some duplicate copies inside. So, i defined my upload table with two primary keys- date and time(and sometimes there are more than one row with the same time and date inside the flat file). These primaries are important to me because i want to use them for later tables and i can't use the direct path and parallel method by using primaries.
    Is there any tool which can find duplicate copies before i use sqlldr. But, the special case here is, that the rows not really duplicated but date and time rows twice. And for my interest it isn't necessary whether there are different values in the second row of the same date and time. The file contains data which is monitored every second and that's enough.
    It would be nice if someone could help me
    cheers

    I simply upload from sqlldr to staging tables first.
    The staging tables allow duplicates then I do what I need to do in regards to duplicates or missing data during the transfer from the staging tables to the real tables.
    The staging tables are also global temporary tables so I don't have to worry about cleaning them up or multiple sessions trampling each other.
    I have also used an external table on the datafile instead of sqlldr, this allows me to get rid of the staging table. But that is only good for very small datasets in the file being loaded.

  • How to write the query to find the duplicate rows?

    Hi,
    How will I find the duplicate rows in the table?
    I have a table called ITEM
    Select item_no,mfg_id from item
    Item Mfg_ID
    178 06278
    178 06589
    238 5489
    289 7895
    289 7596
    Now I want to find only the duplicate rows i.e.,178 & 289 is coming twice.
    How will get the all duplicate rows in the table?

    nihar2 wrote:
    Convert to
    SELECT it.item,
         im.mfg_item,
         im.manufacturer,
         im.description
    FROM (SELECT it.item,
         im.mfg_item,
         im.manufacturer,
         im.description,
         count(it.item) over(partition by it.item order by it.item) cnt
         FROM item it,item_mfg im
         WHERE it.u##item=im.u##item)
    WHERE cnt > 1
    But I tried It show not valid identifier.You can't use the table aliases from the sub-query...
    SELECT item,
           mfg_item,
           manufacturer,
           description 
    FROM (SELECT it.item,
           im.mfg_item,
           im.manufacturer,
           im.description,
           count(it.item) over(partition by it.item order by it.item) cnt
      FROM item it,item_mfg im
      WHERE it.u##item=im.u##item)
    WHERE cnt > 1

  • Deleting BOTH duplicate rows in Excel

    Hi everyone,
    I have just been introduced to Applescript and I was hoping to automate some things at my workplace. One of the first activities that I have been trying to figure out involves Excel 2008, which is running on a G5 (Latest version of Mac OS X updated just today). It involves deleting both duplicates of records--file numbers--in a long one column list (there may soon be thousands of these records piling up, with many duplicates.)
    Someone over at MacScripter ("mikerickson" @ http://macscripter.net/viewtopic.php?id=32340) posted the following code for using Excel autofilter to delete only one instance of each duplicate row:
    *tell application "Microsoft Excel"*
    *set myMessySheet to get worksheet "Sheet1" of workbook "Workbook2.xls"*
    *set myMessyRange to get current region of range "A1" of myMessySheet*
    *set myCleanRange to get resize (get offset (myMessyRange) column offset ((count of columns of myMessyRange) + 1)) row size 1*
    *advanced filter myMessyRange action filter copy copy to range myCleanRange with unique*
    *-- optional deletes dirty range*
    *delete range (entire column of (get resize myMessyRange column size ((count of columns of myMessyRange) + 1))) shift shift to left*
    *end tell*
    This code works great when I copy and paste in Applescript Editor. Now, I need to find all duplicates in my data and delete both of the numbers, leaving only the single instance records/numbers. There are even instances where a number shows up three or more times; it would be great to get rid of those as well.
    Thank you in advance to anyone who can help me with this.

    I think you're going to have a hard time doing this because the original script used Excel to do the heavy lifting (i.e. filter the duplicates). The keyword with unique in the advanced filter is what's doing that.
    Off hand, I don't see an equivalent option for the filter that finds singletons in the list. Without that you'll need to iterate through the list manually, excluding the duplicate entries.

  • How do I find duplicate words in a Numbers spreadsheet?

    Hello, I've created my first document on Numbers and am trying to figure out how to find duplicate words. Ideally, a list of words that repeat in the document and how many times. Is this possible? Thank you in advance for the advice

    It's easy enough to find and count duplicate entries, especially if they are all in a single column, but if you want to count individual words within multi word entries, the problem is more complicated.
    Here's an example for the 'simple' case, using a familiar 155 word passage from English literature.
    The words in the passage are separated into a single line for each word, and stripped of all punctuation. This may be done in Pages, or in Text edit, or in pretty much any word processing software or text editor. Paste the passage into a WP or text document, then use the application's Find/Replace feature to replace all of the spaces with returns. I would also do a second pass replacing all double returns with single returns, then repeat that until Find/Replace reported replacing zero occurrences.
    Punctuation was stripped using Find/Replace
    The prepared list was pasted into column A of a Numbers table.
    Formulas:
    B2: =COUNTIF($A$1:A2,A2)
    C2: =IF(AND(B>1,B=COUNTIF($A,A2)),ROW()-1,999999)
    Fill both down their respective columns to the end of the table.
    The small table is inserted as a Basic table using the Tables button. It contains a Header row, but no Header columns.
    Formula:
    A2: =IFERROR(OFFSET(Table 1 :: $A$1,SMALL(Table 1 :: $C,ROW()-1),COLUMN()-1),"")
    Fill right into B2, then fill both down to the end of the table.
    Descriptions of the functions used, along with their syntax and at least one example of their use in a table are available in the Numbers '09 User Guide, which may be downloaded via the Help menu in Numbers.
    Regards,
    Barry
    PS: Regards to the late Mr. Shakespeare, and thank you for providing the text used.

  • Duplicate rows showing up in a table on the UI

    Hi All,
    We have a VO that returns 6 rows in a table on the UI. The rows become editable when a checkbox(a column in the table) is selected.
    On running it, sometimes we are getting 12 rows on the UI such that the first 6 rows are shown again in the table in the same order.
    When changes are made to this table and saved, only 6 rows are saved in the database table. Also, if 1 row is selected and the duplicate row of this row is not selected, then if we go to some other page and come back, the row that was selected earlier, will be unselected. If both the rows of same values are selected, only then the changes will be saved.
    The VO query has 2 tables. Checked data in both of these tables and executed the query too, but did not find any data issue. Also, we are having an order by clause in the query and the data in the table is not showing up in order.
    This is not occurring consistently but occurring for long durations.
    Can anybody fix this?
    Thanks,
    Sakshi

    Do you still have the "Music Video" Smart Playlist in iTunes? If you right click on a video file, which normally shows up under "Movies" you can pick the video type of Movie, Music Video, or TV Show. When you select "Music Video" the video file drops out of the Movies section and if the Music Video playlist is present will show up there.
    You might have deleted that playlist so it wouldn't be on the iPod either.
    So create a Smart Playlist where the rule is Video Kind IS Music Video...
    Patrick

  • First attempt to remove duplicate rows from a table...

    I have seen many people asking for a way to remove duplicate rows from data. I made up a fairly simple script. It adds a column to the table with the cell selected in it, and adds the concatenation of the data to the left into that new column. then it reads that into a list, and walks through that list to find any that are listed twice. Any that are it marks for DELETE.
    It then walks through to find each one marked for delete and removes them (you must go from bottom to top to do this, otherwise your row markings for delete don't match up to the original rows anymore). Last is to delete the column we added.
    tell application "Numbers"
    activate
    tell document 1
    -- DETERMINE THE CURRENT SHEET
    set currentsheetindex to 0
    repeat with i from 1 to the count of sheets
    tell sheet i
    set x to the count of (tables whose selection range is not missing value)
    end tell
    if x is not 0 then
    set the currentsheetindex to i
    exit repeat
    end if
    end repeat
    if the currentsheetindex is 0 then error "No sheet has a selected table."
    -- GET THE TABLE WITH CELLS
    tell sheet currentsheetindex
    set the current_table to the first table whose selection range is not missing value
    end tell
    end tell
    log current_table
    tell current_table
    set list1 to {}
    add column after column (count of columns)
    set z to (count of columns)
    repeat with j from 1 to (count of rows)
    set m to ""
    repeat with i from 1 to (z - 1)
    set m to m & value of (cell i of row j)
    end repeat
    set value of cell z of row j to m
    end repeat
    set MyRange to value of every cell of column z
    repeat with i from 1 to (count of items of MyRange)
    set n to item i of MyRange
    if n is in list1 then
    set end of list1 to "Delete"
    else
    set end of list1 to n
    end if
    end repeat
    repeat with i from (count of items of list1) to 1 by -1
    set n to item i of list1
    if n = "Delete" then remove row i
    end repeat
    remove column z
    end tell
    end tell
    Let me know how it works for y'all, it worked good on my machine, but I know localization is causing errors sometimes when I post things.
    Thanks,
    Jason
    Message was edited by: jaxjason

    Hi jason
    I hope that with the added comments it will be clear.
    Ask if something is always opaque.
    set {current_Range, current_table, current_Sheet, current_Doc} to my getSelection()
    tell application "Numbers09"
    tell document current_Doc to tell sheet current_Sheet to tell table current_table
    set list1 to {}
    add column after column (count of columns)
    set z to (count of columns)
    repeat with j from 1 to (count of rows)
    set m to ""
    tell row j
    repeat with i from 1 to (z - 1)
    set m to m & value of cell i
    end repeat
    set value of cell z to m
    end tell
    end repeat
    set theRange to value of every cell of column z
    repeat with i from (count of items of theRange) to 1 by -1
    (* As I scan the table backwards (starting from the bottom row),
    I may remove a row immediately when I discover that it is a duplicate *)
    set n to item i of theRange
    if n is in list1 then
    remove row i
    else
    set end of list1 to n
    end if
    end repeat
    remove column z
    end tell
    end tell
    --=====
    on getSelection()
    local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
    tell application "Numbers09" to tell document 1
    set theSheet to ""
    repeat with i from 1 to the count of sheets
    tell sheet i
    set x to the count of tables
    if x > 0 then
    repeat with y from 1 to x
    (* Open a trap to catch the selection range.
    The structure of this item
    «class
    can't be coerced as text.
    So, when the instruction (selection range of table y) as text
    receive 'missing value' it behaves correctly and the lup continue.
    But, when it receive THE true selection range, it generates an error
    whose message is errMsg and number is errNum.
    We grab them just after the on error instruction *)
    try
    (selection range of table y) as text
    on error errMsg number errNum (*
    As we reached THE selection range, we are here.
    We grab the errMsg here. In French it looks like:
    "Impossible de transformer «class
    The handler cuts it in pieces using quots as delimiters.
    item 1 (_) "Impossible de transformer «class » "
    item 2 (theRange) "A2:M25"
    item 3 (_) " of «class NmTb» "
    item 4 (theTable) "Tableau 1"
    item 5 (_) " of «class NmSh» "
    item 6 (theSheet) "Feuille 1"
    item 7 (_) " of document "
    item 8 (theDoc) "Sans titre"
    item 9 ( I drop it ) " of application "
    item 10 ( I drop it ) "Numbers"
    item 11 (I drop it ) " en type string."
    I grab these items in the list
    {_, theRange, _, theTable, _, theSheet, _, theDoc}
    Yes, underscore is a valid name of variable.
    I often uses it when I want to drop something.
    An alternate way would be to code:
    set ll to my decoupe(errMsg, quote)
    set theRange to item 2 of ll
    set theTable to item 4 of ll
    set theSheet to item 8 of ll
    set theDoc to item 10 of ll
    it works exactly the same but it's not so elegant.
    set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
    exit repeat (*
    as we grabbed the interesting datas, we exit the lup indexed by y.*)
    end try
    end repeat -- y
    if theSheet > "" then exit repeat (*
    If we are here after grabbing the datas, theSheet is not "" so we exit the lup indexed by i *)
    end if
    end tell -- sheet
    end repeat -- i
    (* We may arrive here with two kinds of results.
    if we grabbed a selection, theSheet is something like "Feuille 1"
    if we didn't grabbed a selection, theSheet is the "" defined on entry
    and we generate an error which is not trapped so it stops the program *)
    if theSheet = "" then error "No sheet has a selected table."
    end tell -- document
    (* Now, we send to the caller the interesting datas :
    theRange "A2:M25"
    theTable "Tableau 1"
    theSheet "Feuille 1"
    theDoc "Sans titre" *)
    return {theRange, theTable, theSheet, theDoc}
    end getSelection
    --=====
    on decoupe(t, d)
    local l
    set AppleScript's text item delimiters to d (*
    Cut the text t in pieces using d as delimiter *)
    set l to text items of t
    set AppleScript's text item delimiters to "" (*
    Resets the delimiters to the standard value. *)
    (* Send the list to the caller *)
    return l
    end decoupe
    --=====
    Have fun
    And if it's not clear enough, you may ask for more explanations.
    Yvan KOENIG (from FRANCE mardi 27 janvier 2009 21:49:19)

  • ABAP / Query to Identify Duplicate Rows in Cube

    Dear Experts,
    We have a situation were some of our Cubes (due to compression and varying levels of forceful reloads) now contain duplicate rows.
    What I need to know is :-
    1) Is there a way to identify duplicate rows where one of the characteristics are different but all key figures are identical.
    2) If so what is easier to achieve, ABAP routine/program or Query
    3) If ABAP suggestions on how to code such
    4) If query same.
    What I need it to do is tell me which ClaimNo record (Primary Key) has duplicates and what characteristic has caused it.
    I know I am asking for a lot but I really need to get this resolved as it's causing mayhem and trying to pinpoint these records is both time consuming and painful.  What we are looking to do with the records is establish how they became duplicated so we can prevent this happening in the future.
    Your help as always much appreciated.
    Regards
    Craig
    Message was edited by: Craig Armstead

    Hi Craig,
    My previous answer can find out what all cubes and data targets have been loaded based on a request.
    Actually for your query. The following information will be surely useful.
    tables: /BIC/**(source ) , /BIC**(target)
    parameter : fieldname like /BIC/****-fieldname ( In ur case the it can be primary key or Duplicate entry )
    data: itab_source  like /BIC/*** occurs 0 with header line,
          itab_destination like /BIC/*** occurs 0 with header line.
    data: wa_itab_destination like line of itab_destination.
    select *
      from /BIC/*****
      into corresponding fields of table itab_source.
      where fieldname = fieldname.
    ******Include your piece of code which is for deleting records
    Delete adjacent duplicates from itab_source comparing characteristic ( i.e  duplicate characteristic you specified)
    ****Use this to delete the ODS Data before writing into it
    call function 'RSDRI_ODSO_DELETE_RFC'
      exporting
        i_odsobject  = 'ODS Name'
        i_delete_all = 'X'.
    if sy-subrc = 0.
      loop at itab_source.
        move-corresponding itab_source to itab_destination.
        append itab_destination.
      endloop.
      modify /BIC/*** from table itab_destination[].   “target being written from itab.
      commit work.
    endif.
    Please Reward points if this helps really.
    Thanks,
    Srinivas.

  • Lookup transformation to avoid duplicate rows? - SSIS 2005

    Hi,
    I'm maintaning a SSIS 2005 pkg. I need to read a flat file to write on a SQL Server table, avoiding duplicates.
    I can have duplicates rows into the flat file to import and I need to prevent the insert of any rows already existing in the SQL Server table.
    So, I think to use a lookup transformation. I've created a flat file source, then I connect it to a lookup transformation and inside it I've specified as the reference table the SQL Server destination table. Then, I've checked the available lookup columns
    each adding as a new column: but the lookup task has arised an error and so I've specified as lookup operation the replacement. For each unmatching I need to write on the SQL Server table (the reference table in the lookup). For the lookup output error I've
    indicate to ignore failure. Other steps?
    However, when I run the pkg then inside the SQL Server destination table I can see only NULL values, but I want to see the rows don't already present in the table.
    Any suggests to me, please? Thanks

    Hi,
    I'm using SSIS 2005 as reported in the title of the post.
    I could have duplicates inside the source file and the existing table could haven't any rows.
    Thanks
    If you dont have any rows in existing table, then they will go through Error output in lookup task. For duplicates, lookup task will find matches and will go through lookup match output
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for

  • Windows 8.1 - Sysprep, CopyProfile and Default Applications

    Hello, I'm absolutely at the end of my rope with this one. My organization wants to deploy Windows 8.1 Professional to a small but not insignificant number of workstations. Due to a host of reasons beyond my control, higher ups have decided UAC needs

  • My images is exporting bigger then my art board? CS6

    Hi i have a artboart set to 241 × 283 but when i export my image it exports it to 506 × 590 so im confused on all of this please help? Thanks Cody

  • Mounting the same VHDX from 2 simultaneous user sessions?

    Hi, I need to mount the same VHD or VHDX file from 2 different user sessions. My file is BitLocker-encrypted, NTFS-formatted (I can reformat to an other filesystem if needed). It resides on a network location, a samba share. My scenario is the follow

  • Xd01 user exit/badi

    Hi Experts,                  My requirement is that,i have fetch customer details on customer create/change.I am able to fetch all fields of kna1 through exit sapmf02d.I am not able to fetch adr2-tel_number(mobile no),                                

  • Webkitwebprocess.exe has stopped working

    not sure how to stop my safari from crashing every once in a while; message shows as webkitwebprocess.exe has stopped working. any help, most welcome! :-)