作者:陨落星辰W_955 | 来源:互联网 | 2023-01-02 14:37
我有一个表listed_users
有两个TEXT列,code
并且username
:
code | username
-----|---------
aa | john_doe
ab | jane_doe
ca | john_doe
ca | john_doe <-- duplicate
da | ryan_doe
我想编写一条命令来删除重复的命令,例如ca | john_doe
,其中相同的信息会出现在多行的两列中。
1> CL...:
To delete one of a pair of duplicate rows, you must have some mechanism to identify it. In SQLite, this would be the rowid.
The following query returns the rowid
values of all the rows you want to keep, i.e., one row for each unique code/name combination:
SELECT min(rowid)
FROM listed_users
GROUP BY code, username;
You want to delete all rows not in that list:
DELETE FROM listed_users
WHERE rowid NOT IN (SELECT min(rowid)
FROM listed_users
GROUP BY code, username);