MySQL 删除重复数据(两个字段)

susan1992 2013-12-27 11:20:53
表full中userID和movieID两个字段确定一条唯一的数据。
现在表中有少量重复数据和大量非重复数据。
重复数据中,preference列和timestamp列不为空的这些,需要保留;preference列和timestamp列为空的这些需要删除,应该怎么办?

+------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+-------+
| userID | int(11) | NO | | 0 | |
| movieID | int(11) | NO | | 0 | |
| preference | int(11) | YES | | NULL | |
| timestamp | int(11) | YES | | NULL | |
+------------+---------+------+-----+---------+-------+

初学者,希望答案详细:) 感激不尽
...全文
172 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Joe_hunter 2013-12-31
  • 打赏
  • 举报
回复
先找到重复的数据放在一张表,然后源表和新表关联删除重复且为空的记录。
u010019315 2013-12-31
  • 打赏
  • 举报
回复
delete from 表 where preference is null and timestamp is null
susan1992 2013-12-27
  • 打赏
  • 举报
回复
有大量的、需要保留的、非重复数据的这两列也是空的,想要删除重复的、这两列为空的数据。我觉得需要个if条件什么的……但是mysql里不知道该怎么写
引用 1 楼 WWWWA 的回复:
举例说明  delete from tt where preference is null and timestamp is null
WWWWA 2013-12-27
  • 打赏
  • 举报
回复
举例说明  delete from tt where preference is null and timestamp is null
susan1992 2013-12-27
  • 打赏
  • 举报
回复
引用 3 楼 WWWWA 的回复:
举例说明 表中有无唯一标识的字段
没有。两个字段才可以唯一标识。
WWWWA 2013-12-27
  • 打赏
  • 举报
回复
举例说明 表中有无唯一标识的字段

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧