Find MySql duplicated rows

Discussion in 'MySQL' started by jalex, Aug 26, 2006.

  1. #1
    How do i find the duplicate rows from a table?
    I don't want to find duplicate entries for a column.. i have 30 columns in the table and i want to find duplicates rows that have exactelly same data for all columns

    thanks
     
    jalex, Aug 26, 2006 IP
  2. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Use a union or sub-select in the from.

    select * from table1 where NOT in (select * from table2) (not tested but it should be something like this, hehe
     
    ccoonen, Aug 26, 2006 IP
  3. void

    void Peon

    Messages:
    119
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    SELECT * FROM `Table` WHERE `Key` != `Key` AND `Column1` = `Column1` AND `Column2` = `Column2` AND `Column3` = `Column3` etc
     
    void, Aug 26, 2006 IP
  4. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #4
    That wouldn't work would it? That would be comparing each row to itself, wouldn't it???

    I would just use a self join.

    SELECT table1.c1, table1.c2, table1.c3, table2.c1, table2.c2, table2.c3
    FROM table1
    SELF JOIN ON table2.c1 = table1.c1 AND table2.c2 = table1.c2 AND table2.c3 = table1.c3;

    The first column set will be all of the data from the table.

    The 2nd column set should only be the duplicate content.
     
    drewbe121212, Aug 26, 2006 IP
  5. void

    void Peon

    Messages:
    119
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Nope, compares every row to every other row.

     
    void, Aug 27, 2006 IP
  6. Gatorade

    Gatorade Peon

    Messages:
    2,130
    Likes Received:
    222
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Gatorade, Aug 27, 2006 IP
  7. void

    void Peon

    Messages:
    119
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Scrap that - needed to do the same today and it didn't work :( . Could have sworn I did exactly that 2 weeks ago though :confused:
     
    void, Aug 29, 2006 IP
  8. void

    void Peon

    Messages:
    119
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #8
    After some Gatorade style phpfreaks and headscratching I used

    SELECT *
    FROM `Table1` AS T1, `Table1` AS T2
    WHERE T1.`Key` != T2.`Key`
    AND T1.Col1 = T2.Col1
    AND T1.Col2 = T2.Col2
    ORDER BY T2.Col1
    Code (markup):
    etc
     
    void, Aug 29, 2006 IP