0

我弄乱了我的数据库中的几个表,结果相似但键不同。结果是这样的:

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

我想删除那些重复的行,以便结果如下:

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

我试过SELECT * DISTINCT 2 FROM TABLE了,但没有用。对不起,我不能说得更好!

4

2 回答 2

0

尝试

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

SQLFiddle 示例

于 2012-07-29T17:37:42.367 回答
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
    );
于 2012-07-29T17:44:15.747 回答