【求助】请教SQLITE如何删除表内重复的记录
表如下
SID TIT
10001 hello1
10002 hello2
10002 hello3
10003 hello4
执行后的效果
SID TIT
10001 hello1
10002 hello2
10003 hello4
------解决方案--------------------
SQL code
sqlite> select * from Yookey;
sid|tit
10001|hello1
10002|hello2
10002|hello3
10003|hello4
sqlite>
sqlite> delete from Yookey where tit not in (select min(tit) from Yookey group b
y SID);
sqlite> select * from Yookey;
sid|tit
10001|hello1
10002|hello2
10003|hello4
表如下
SID TIT
10001 hello1
10002 hello2
10002 hello3
10003 hello4
执行后的效果
SID TIT
10001 hello1
10002 hello2
10003 hello4
------解决方案--------------------
SQL code
sqlite> select * from Yookey;
sid|tit
10001|hello1
10002|hello2
10002|hello3
10003|hello4
sqlite>
sqlite> delete from Yookey where tit not in (select min(tit) from Yookey group b
y SID);
sqlite> select * from Yookey;
sid|tit
10001|hello1
10002|hello2
10003|hello4
sqlite>
删除后要是想压缩库文件:
Sqlite3的数据库,在删除数据时并不会回收空间,因此Sqlite3提供了一个特殊操作:VACUUM,调用它,我们可以压缩数据库。