0

I messed up a couple of tables in my database with similar results but different keys. The results are something like this:

1   |2   |3   
5   |25  |25
6   |25  |25
7   |31  |31
8   |31  |31

I would like to delete those duplicate rows so that the results are like this:

1   |2   |3
5   |25  |25
7   |31  |31

I tried SELECT * DISTINCT 2 FROM TABLE but that didn't work. Sorry I can't word it much better!

Teun Zengerink
  • 4,277
  • 5
  • 30
  • 32

2 Answers2

0

try

delete from your_table
where id not in (
                 select * from (select min(id) from your_table
                                group by col2, col3)
                 t_alias
                )

SQLFiddle example

juergen d
  • 201,996
  • 37
  • 293
  • 362
0
DELETE FROM the_table dt
WHERE EXISTS ( SELECT *
    FROM the_table ex
    WHERE ex.col2 = dt.col2
    AND ex.col3 = dt.col3
    AND ex.id < dt.id
    );
wildplasser
  • 43,142
  • 8
  • 66
  • 109