删除重复记录
时间:2011-11-11
来源:互联网
在数据库里面有两张表:
A表:
xhid clothingid nums
1 822001Ai2 1
B表:
clothingid nums
822001Ai2 1
现在的情况是这样,将A表里面,clothingid在B表中存的,并且A表中存在多条记录的删除,
语句要怎么写;
比如:
A表中的clothingid,有3个记录都是822001Ai2,B表里面也存在着clothingid为822001Ai2的记录,
现在要把A表中clothingid为822001Ai2的记录删除到剩下一条;
不知语句应如何写;
请高手帮忙;
A表:
xhid clothingid nums
1 822001Ai2 1
B表:
clothingid nums
822001Ai2 1
现在的情况是这样,将A表里面,clothingid在B表中存的,并且A表中存在多条记录的删除,
语句要怎么写;
比如:
A表中的clothingid,有3个记录都是822001Ai2,B表里面也存在着clothingid为822001Ai2的记录,
现在要把A表中clothingid为822001Ai2的记录删除到剩下一条;
不知语句应如何写;
请高手帮忙;
作者: wuzhj3107 发布时间: 2011-11-11
SQL code
delete t from a t where exists(select 1 from b where clothingid=t.clothingid) and exists(select 1 from a where clothingid=t.clothingid and xhid<t.xhid)
作者: fredrickhu 发布时间: 2011-11-11
delete a
from A t where exists(select 1 from A where clothingid=t.clothingid and xhid >t.xhid)
and exists(select 1 from B where clothingid=t.clothingid)
from A t where exists(select 1 from A where clothingid=t.clothingid and xhid >t.xhid)
and exists(select 1 from B where clothingid=t.clothingid)
作者: ssp2009 发布时间: 2011-11-11
SQL code
delete t1 from A as t1 inner join B as on t1.clothingid=b.clothingid where t1.xhid not in(select 1 from A where clothingid=t1.clothingid)
作者: roy_88 发布时间: 2011-11-11
可能我说的不是很明白,A表中的xhid不是主键,此字段的值是允许重复的,
xhid+clothingid不可以出现重复;
xhid+clothingid不可以出现重复;
作者: wuzhj3107 发布时间: 2011-11-11
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28