Eliminating duplicates from subquery...

What is the best way to eliminate duplicates from a subquery:
SELECT dept_no, dept_name
FROM dept D
WHERE EXISTS (
SELECT 'X'
FROM emp E
WHERE E.dept_no = D.dept_no);
OR
SELECT dept_no, dept_name
FROM dept D
WHERE ( SELECT 'X'
FROM emp E
WHERE E.dept_no = D.dept_no AND ROWNUM < 2);
Thanks!

>
UPDATE TABLE1
SET COL1 = (
SELECT DISTINCT COL1
FROM TABLE2, TABLE3
WHERE TABLE2.ID = TABLE3.ID
You need to refine your example. At present you appear to be updating every row in table1 to the same value - but only if col1 (which could be from table2 or table3 - or might be accidental capture from table1) holds just one distinct value across the query; but it looks as if you're likely to get 'single row subquery returns more than one row[ as an error.
I guess you're trying to do something LIKE:
update t1
set t1.col1 = (
  select t2.col2
  from t2
  where  t2.colx = t1.coly
  and  exists (
    select null
    from t3
    where t3.id = t2.id
)The most efficient access path depends on how many rows will have to be examined in each table, and how many times you will have to jump to another table to find related data - and if your query is roughly the shape of this one, the optimizer may be able to transform it in a variety of ways to find an efficient access path.
As it stands, my example will be setting col1 to null whenever there is no match for coly in table t2 - and the optimizer would have to drive off t1 looking at every row to do this. Your requirement, and available predicates, indexes and constraints, may allow, or force, a completely different strategy.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk

Similar Messages

  • Question. Eliminating duplicate identical rows.

    Question. Eliminating duplicate identical rows.
    --1. assume we have this table
    create table T
    tabid int not null,
    crdate datetime not null
    go
    --2.Now load the following data:
    insert into T values (1, '1/1/2003')
    insert into T values (1, '1/1/2003')
    insert into T values (2, '2/1/2003')
    insert into T values (2, '2/1/2003')
    insert into T values (3, '3/1/2003')
    insert into T values (3, '3/1/2003')
    insert into T values (4, '4/1/2003')
    insert into T values (4, '4/1/2003')
    go
    -- 3. Run this query to discover duplicates
    select tabid, crdate, count(*)
    from T
    group by tabid, crdate
    having count(*) > 1
    go
    --4. Result is something like this
    1     2003-01-01 00:00:00.000     2
    2     2003-02-01 00:00:00.000     2
    3     2003-03-01 00:00:00.000     2
    4     2003-04-01 00:00:00.000     2
    Question
    How do I eliminate duplicates and reduce table by 50%?

    I think this what you want:
    SQL> create table test ( c1 varchar2(5));
    Table created.
    SQL> insert into test values ( 'a' );
    1 row created.
    SQL> insert into test values ( 'b');
    1 row created.
    SQL> insert into test values ( 'a');
    1 row created.
    SQL> insert into test values ( 'c');
    1 row created.
    SQL>
    SQL> select c1 from test group by c1 having count(*)>1;
    C1
    a
    SQL> delete from test where c1 in
    2 ( select c1 from test group by c1 having count(*)>1);
    2 rows deleted.
    SQL>
    SQL> select * from test;
    C1
    b
    c
    SQL>
    Joel P�rez

  • Best app to remove duplicates from iTunes 2014

    Hi All,
    I've been trying to research the best application to sort and remove duplicates from my iTunes library. I have over 7000 songs and iTunes built in duplicate finder doesn't look at the track fingerprint, which is useful for those songs which are labelled "Track_1" etc.
    Has anyone reviewed any recent products? I was looking at TuneUp, but after reading so many negative comments, I've decided not to go down that path. I would prefer a program that did most of the work for me, due to the amount of songs. Happy to pay for a good product...
    I do have MusicBrainz Picard, which has done a great job of tagging, but don't remove duplicates.
    Thanks in advance :-)

    Tune up is a great app.  When they moved from version 2 to version 3 is when it went to crap and all heck broke loose.  They shut their doors  but they have since re opened and went back to developing  version 2.  I use that version and I am pretty happy with it as being an overall cleanup utility.  I also use Musicbrainz and a couple of other utilities but in the end if you have an enormous library 20k plus then you are going to have a few slip through.  I would probably go with Tuneup if I were you and a thorough third party duplicate finder.  Dupe Guru's music edition seems to do a pretty good job.

  • How to delete duplicates from iTunes but not hard drive

    I'm running iTunes 10 and have my music stored on both my NAS drive and backup drive.  Each track appears twice on iTunes: once as lossless for streaming and and once as compressed AAC files for synching to ipods and iphones.
    For some reason, when my PC is turned on after being turned on, the linkstation cannon be 'seen' by iTunes, and therefore if I try to play a track, 'the original file cannot be found'.  If I use the 'add folder to library' option in the 'file' dropdown menu, the tracks are located again.
    Unfortunately, I the last time I did this it resulted in 4 copies of each song on itunes; 2 lossless and 2 AAC.
    I have 2 questions:
    Firstly is there an easy way to delete the duplicates from my iTunes library so that I am left with only 1 lossless and one AAC copy, but not deleing the files from my NAS and backup drive?
    Is there a way I can just store my music as lossless, but convert it easily to aa more compressed format for synching to iphone and ipod?
    Thanks!

    You can try my new DeDupe script. It should be able to get rid of the redundant copies while keeping one copy of each track in each format. See this thread for background.
    I've not used the feature, but iTunes can downsample to 128k AAC on the fly as it syncs your devices. Of course you might find the process is too slow for your needs or find that 128k is too much compression.
    tt2

  • Deleting Duplicates from a table

    Its a huge table with 52 fields and 30k rows. I need to delete the duplicates based on one of the fields. GROUP BY is taking a lot of time. Is there a quicker way to delete the duplicates using SQL.
    Thanks.

    How many duplicates have you got? Do you have even a vague idea? 1%? 20%? 90%?
    One way would be to add a unique constraint on the column in question. This will fail, of course, but you can use the EXCEPTIONS INTO clause to find all the ROWIDs which have duplicate values. You can then choose to delete those rows using a variant on teh query already posted. You may need to run %ORACLE_HOME%\rdbms\admin\utlexcptn.sql to build the EXCEPTIONS table first.
    This may seem like some unnecessary work, but the most effective way of deleting duplicates from a table is to have relational integrity constraints in place which prevent you having duplicates in the first place. To paraphrase Tim Gorman, you can't get faster than zero work!
    Cheers, APC

  • HT2905 i have just followed all the insrtuctions in support to remove duplicates from my library but now most of my musicis gone except for my recent purchases. How come and how do i fix it?

    i have just followed all the instructions in support to remove duplicates from my library but now most of my music is gone except for my recent purchases. How come and how do i fix it?

    Final Cut is a separate, higher end video editor.  The pro version of iMovie.
    Give iPhoto a look at for creating the slideshow.  It's easy to assemble the photos in an album in iPhoto, put them in the order you want and then make a slideshow of them.  You can select from various themes and transitions between slides and add music from your iTunes library.
    When you have the slidshow as you want use the Export button at the bottom of the iPhoto window and export with Size = Medium or Large.
    Save the resulting Quicktime movie file in your Movies folder.
    Next, open iDVD, choose your theme and drag the QT movie file into the menu window being careful to avoid any drop zones.
    Then follow this workflow to help assure the best qualty video DVD:
    Once you have the project as you want it save it as a disk image via the File ➙ Save as Disk Image  menu option. This will separate the encoding process from the burn process. 
    To check the encoding mount the disk image, launch DVD Player and play it.  If it plays OK with DVD Player the encoding is good.
    Then burn to disk with Disk Utility or Toast at the slowest speed available (2x-4x) to assure the best burn quality.  Always use top quality media:  Verbatim, Maxell or Taiyo Yuden DVD-R are the most recommended in these forums.
    The reason I suggest iPhoto is that I find it much easier to use than iMovie (except for the older iMovie 6 HD version).  Personal preferences showing here.

  • Delete Duplicates from internal table with object references

    Hi
    How can I delete duplicates from an internal table in ABAP OO based on the value of one of the attributes?
    I have created a method, with the following code:
      LOOP AT me->business_document_lines INTO l_add_line.
        CREATE OBJECT ot_line_owner
          EXPORTING
            i_user      = l_add_line->add_line_data-line_owner
            i_busdoc = me->business_document_id.
          APPEND ot_line_owner TO e_line_owners.
      ENDLOOP.
    e_line_owners are defined as a table containing only object references.
    One of the attribute of the object in the table is called USER. And I would like to do a "delete ADJACENT DUPLICATES FROM e_line_owners", based on that attribute.
    How can do this?
    Regards,
    Morten Nielsen

    Hello Morten
    Assuming that the instance attribute is <b>public </b>you could try to use the following coding:
      SORT e_line_owners BY table_line->user.
      DELETE ADJACENT DUPLICATES FROM e_line_owners
        COMPARING table_line->user.
    However, I am not really sure (cannot test myself) whether <b>TABLE_LINE</b> can be used together with SORT and DELETE.
    Alternative solution:
      DATA:
         ld_idx    TYPE sy-tabix.
      LOOP AT e_line_owners INTO ls_line.
        ld_idx = syst-tabix + 1.
        LOOP AT e_line_owners TRANSPORTING NO FIELDS FROM ld_idx
                       WHERE ( table_line->user = ls_line->user ).
          DELETE e_line_owners INDEX syst-tabix.
        ENDLOOP.
      ENDLOOP.
    Regards
      Uwe

  • Delete duplicates from query output

    Hello,
      I would like to delete duplicated records before the output of a SAP query
    I tried writing in SQ02 in additional coding, under "Free coding":
    data %dtab type standard table of /1BCDWB/IQ000000001053 with header line.
    sort %dtab by vbeln posnr.
    DELETE ADJACENT DUPLICATES FROM %dtab.
    In this way I get the short dump when running the query: "Statement is not accessible.".
    If I declare %dtab in the additional coding under "DATA", when I run the query I get the error "%DTAB" has already been declared.".
    If I don't declare %dtab, I can't generate the infoset.
    Do you have any suggestion about the way of obtaining this result?
    Thanks in advance for your support.
    Best regards,
    Andrea

    Hello,
      I didn't find any solution to this problem. I choosed another way: I asked an ABAPer to develop a report to get the same information I wanted to get with the query, as in the ABAP report there's more "space to move".
    Best regards,
    Andrea

  • Delete duplicate from internal table

    HI Abapers,
    I have a query on how to remove the duplicates from an internal table
    My internal table data is as follows :
    Cno    Catg1  Catg2
    01       0         1000
    01      2000         0
    I want to get only one record as
    01   2000  1000
    How to  get the result.
    I tried sorted by cno and used delete duplicates but it was not helpful.
    Is there any other alternative to get this done
    Please help me.
    Regards,
    Priya

    check it out with delete adjacent duplicate records
    Deleting Adjacent Duplicate Entries
    To delete adjacent duplicate entries use the following statement:
    DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
                                      [COMPARING <f1> <f 2> ...
                                                 |ALL FIELDS].
    The system deletes all adjacent duplicate entries from the internal table <itab>. Entries are duplicate if they fulfill one of the following compare criteria:
    Without the COMPARING addition, the contents of the key fields of the table must be identical in both lines.
    If you use the addition COMPARING <f1> <f 2> ... the contents of the specified fields <f 1 > <f 2 > ... must be identical in both lines. You can also specify a field <f i > dynamically as the contents of a field <n i > in the form (<n i >). If <n i > is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length.
    If you use the addition COMPARING ALL FIELDS the contents of all fields of both lines must be identical.
    You can use this statement to delete all duplicate entries from an internal table if the table is sorted by the specified compare criterion.
    If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.

  • How to choose in Delete Duplicates from internal table?

    Now I need to delete Duplicates from internal table,
    So at first I sort
    than I delete duplicate
    Sort itab1 BY Company_Code  Asset_No Capital_Date.
          DELETE ADJACENT DUPLICATES FROM itab1 COMPARING Company_Code  Asset_No  Capital_Date
    Company_Code
    Asset_No
    Capital_Date
    Remark
    BC35
    1515593
    20021225
    Helen
    BC35
    1515593
    20021225
    Common Asset
    BC35
    1515594
    20030109
    Judy
    BC35
    1515594
    20030109
    Common Asset
    But here comes my problem~If I want to delete the Common Asset in Remark Column,how I let it choose the right one to do it?

    Hi Jack
    Try the below coding..
    Report zsamp.
    types: begin of t_tab,
            comp_code(4) type c,
            ***_no(7) type n,
            cap_date type d,
            remark type string,
            end of t_tab.
    data: i_tab type TABLE OF t_tab,
           w_tab type t_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515593'.
    w_tab-cap_date = '20021225'.
    w_tab-remark = 'Helen'.
    append w_tab to i_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515593'.
    w_tab-cap_date = '20021225'.
    w_tab-remark = 'Common Asset'.
    append w_tab to i_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515594'.
    w_tab-cap_date = '20030109'.
    w_tab-remark = 'Judy'.
    append w_tab to i_tab.
    w_tab-comp_code = 'BC35'.
    w_tab-***_no = '1515594'.
    w_tab-cap_date = '20030109'.
    w_tab-remark = 'Common Asset'.
    append w_tab to i_tab.
    sort i_tab by remark.
    delete ADJACENT DUPLICATES FROM i_tab COMPARING remark.

  • Trouble with iCloud Contacts & Calender / duplicates from system failure

    Duplicates do appear on iPad Contacts and even duplicate birthday entries.
    Even on iCloud.com the birthday entries are duplicate.
    The problem is when you delete a duplicate contact on iPad you lose both!
    Check on iCloud.com if the contact is really a duplicate (from the sync process?).
    Please Apple resolve the problem!
    Peter

    Resolving duplicate calendars
    Resolving duplicate contacts

  • How to filter duplicates from XMLListCollection

    I have been trying to filter duplicates from XMLListCollection using FilterFunction.  However, it filters on the main XML tag, which happens to be the same value on all tags in this particular XML.  The values only vary in the parameters, and I need to filter the duplicates on one of them.  Is there any way to do that?

    yep, there are several ways out there
    The easy oneDo not add duplicates to the XMLListCollection
    Complicated one, extend XMLListCollection with Boolean property 'strict', override method addItemAt and trace duplicates in there.
    Super easy one is to drop XMLListCollection usage in favor of Dictionary class, it's natural capabilities will allow you to maintain strict rule for your data, just use distiction property as a key value with Dictionary class, and you are done

  • ORA 600, duplicate from RAC to NON-RAC

    Hi Experts,
    I'm trying to restore Production database for development purpose point in time recovery
    environment:
    ASM: 11gR1
    DB: 10gR2
    At the end of internal duplicate steps i have faced error
    contents of Memory Script:
    Alter clone database open resetlogs;
    executing Memory Script
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03002: failure of Duplicate Db command at 12/16/2010 05:37:06
    RMAN-03015: error occurred in stored script Memory Script
    RMAN-06136: ORACLE error from auxiliary database: ORA-01152: file 3 was not restored from a sufficiently old backup
    ORA-01110: data file 3: '+DG1/dev/datafile/sysaux.534.737875511'Later i try to apply archives from production.. i have copied those and i started recovery .. i faced internal errors.
    SQL> recover database using backup controlfile;
    ORA-00283: recovery session canceled due to errors
    ORA-00600: internal error code, arguments: [kcvhvdf_1], [], [], [], [], [], [],
    [], [], [], [], []after a lot of workaround i found one doc from metalink
    *Duplicate from active database raises ORA-01194 if one thead is closed [ID 1059699.1]*
    but i checked thread status by gv$thread.. it is looking open from last month..
    any other way to find closed threads?
    so what could be the reason.
    I have no time to raise an SR now.. any ideas will be highly appriciated.
    Thanks
    Edited by: CKPT on Dec 17, 2010 11:09 PM

    I am about to use this hidden parameter (_allow_resetlogs_corruption=true
    ) due to the almost identical problem you experienced.
    What are the risks and what next to do when I open the database?There is lot of RISK
    I tried to recover manually using existing archives, But no use.
    Raised an SR. as a last option provided by support and used that parameter, But this parameter is not suggestible, Before doing such thing, better to take backup of database(mount - cold backup).
    This thread is almost 7 months old, if you have any issue create a new thread.

  • How do i delete duplicates from my music library. After updating my iTunes the "Show Duplicates" option does not appear in the menu

    How do i delete duplicates from my music library. After updating my iTunes the "Show Duplicates" option does not appear in the menu

    If you are on Version 11.0.1 rather than 11 Apple put it back in
    View > Show Duplicates
    Option + View > Show Exact Duplicates
    so if you are on 11 upgrade to 11.0.1 and you will have it

  • HT2905 I want to delete duplicates from my iTunes music but cannot see "Display Exact Duplicates" in File menu.

    Hi,
    I want to delete duplicates from my iTunes music but and iTunes help says to click on "Display Exact Duplicates" in File men but I don't appear to have this function.  Where else can I look?

    Thanks Kappy. I had just found it but thanks reply.  Next question is:  Is there a quick way to then delete the duplicates without having to select each one and delete?

Maybe you are looking for