标签:
一. 查找重复记录
1. 查找全部重复记录
Select * From 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)
2. 过滤重复记录(只显示一条)
Select * From HZT Where ID In (Select Max(ID) From HZT Group By Title)
注:此处显示ID最大一条记录
二. 删除重复记录
1. 删除全部重复记录(慎用)
Delete 表 Where 重复字段 In (Select 重复字段 From 表 Group By 重复字段 Having Count(*)>1)
2. 保留一条(这个应该是大多数人所需要的)
Delete HZT Where ID Not In (Select Max(ID) From HZT Group By Title)
注:此处保留ID最大一条记录
delete from 表名 where rowid in (select rowid from 表名 order by 字断 desc limit 条数 offset 从第几行)
"TRUNCATE table ‘表名‘"; "drop table ‘表名‘";
查找的字断是字串时用法如下
sprintf(sql, "SELECT * FROM GroupTable where gid==‘%s‘ ORDER BY gid asc", [gid UTF8String]);
并列条件如下:
sprintf(sql, "SELECT * FROM FriendTable where type==%d AND uid==%s ORDER BY name asc",type, [uidUTF8String]);
获取所有字断中如果重复就可获取一条最小的ID
sprintf(sql, "SELECT * FROM CarTable where Id In (SELECT Min(Id) form CarTable Group By 字断) ORDER BY carId asc");
标签:
原文地址:http://www.cnblogs.com/mumoozhu/p/4582833.html