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!

T. Zengerink
  • 4,189
  • 5
  • 29
  • 31

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
  • 195,137
  • 36
  • 275
  • 343
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
  • 41,380
  • 7
  • 58
  • 102