GeekInterview.com
Results 1 to 6 of 6

duplicate records deletion?

This is a discussion on duplicate records deletion? within the Databases forums, part of the category; Hi gudmrng to all, This is Sathish. Q. A table contains 50 records in that 25 recs are duplicate how to delete duplicate records? Send queries to this mail inturi86@gmail.com...

  1. #1
    chowdary86 is offline Junior Member Array
    Join Date
    Feb 2011
    Answers
    1

    duplicate records deletion?

    Hi gudmrng to all,
    This is Sathish.
    Q. A table contains 50 records in that 25 recs are duplicate how to delete duplicate records?

    Send queries to this mail inturi86@gmail.com


  2. #2
    admin is offline Administrator Array
    Join Date
    May 2006
    Answers
    985

    Re: duplicate records deletion?

    Hello, Which database you are using .. Cheers, Chandra


  3. #3
    kethinenisarath is offline Junior Member Array
    Join Date
    Feb 2011
    Answers
    5

    Re: duplicate records deletion?

    Dear All.
    finding the duplicate records :
    select * from emp
    where sal in (select sal from emp
    group by sal
    having count(1)>1);


    2.duplicate records deletion:
    delete emp
    where sal in (select sal from emp
    group by sal
    having count(1)>1)

    Thanks &Regards,
    kethinenisarath

    Last edited by kethinenisarath; 03-08-2011 at 02:47 PM.

  4. #4
    ashalalaxmi2002 is offline Contributing Member Array
    Join Date
    Sep 2007
    Answers
    40

    Re: duplicate records deletion?

    Hi,

    If your database is oracle then by using ROWID psuedo column you can delete the duplicate records.see below syntax

    delete from where rowid not in(select max(rowid) from group by .

    eg:i want to delete the duplicate records from emp table.

    delete from emp where rowid not in(select max(rowid) from emp group by empno);

    Thanks,
    vl


  5. #5
    Naveen Kumar39 is offline Junior Member Array
    Join Date
    May 2011
    Answers
    1

    Re: duplicate records deletion?

    DELETE FROM table_name WHERE rowid NOT IN (SELECT max(rowid) FROM table_name GROUP BY id);

    for further study on PL SQL you can visit.


  6. #6
    Melisa is offline Junior Member Array
    Join Date
    Aug 2011
    Answers
    18

    Re: duplicate records deletion?

    It will be helpful especially when deletion is related to the date column:
    DELETE FROM Table t1 WHERE COLUMN_NAME < (SELECT MAX(COLUMN_NAME) FROM Table T2 WHERE T1.COL= T2.COL);»

    Thanks!!


    •    Sponsored Ads