Remove almost duplicate rows

自闭症网瘾萝莉.ら 提交于 2019-12-13 17:10:51

问题


I have an Sqlite3 database with a table like this:

Table(com1, com2)

A || B
B || A
C || D
D || B
B || D

If I have 2 rows: A || B, and B || A, I want to delete one of them (I don't care which one).

So to obtain:

A || B
C || D
D || B

I've read the many asks about duplicate rows but I cant find something like this. Thanks for any help.


回答1:


I think solution for your problem should look like this:

SELECT
    t1.val1,t1.val2
FROM table AS t1
JOIN table AS t2 ON (
    (t1.val1=t2.val2) AND (t1.val2=t2.val1)
) WHERE t1.val1<=t1.val2

where table is the name of your table and val1 and val2 are names of columns in that table.



来源:https://stackoverflow.com/questions/13209289/remove-almost-duplicate-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!