开发者

Keep first and remove dupliciate rows only using sqlite

开发者 https://www.devze.com 2023-01-19 12:58 出处:网络
Maybe i should do this in C# but i have more then one row with linkId X. I would like to remove it but i am unsure how. In code i could just use a foreach from 0 to n and remove any f开发者_StackOverf

Maybe i should do this in C# but i have more then one row with linkId X. I would like to remove it but i am unsure how. In code i could just use a foreach from 0 to n and remove any f开发者_StackOverflowound rows with a greater (or !=) id but thats in code. Is there a less difficult way of doing it using sqlite?


Assuming the table's name is tableName and there is a primary key field named id, the following sql would do it. I think the following SQL query is general enough and should be able to be executed under any database engine.

delete from tableName
where id not in (
    select min(id) from tableName
    group by linkId
)
0

精彩评论

暂无评论...
验证码 换一张
取 消