【数据库】 关联多表删除重复数据

delete table
from table a,
(
	select b.val1 ,b.val2 ,COUNT(1) as cnt
	from table b
	group by b.val1 ,b.val2 
	haval1g COUNT(1) > 1
)b
where a.val1 = b.val1 and a.val2 = b.val2
and a.id not in (
	select MAX(id) as id
	from table a
	group by val1 ,val2 
	haval1g COUNT(1) > 1
)

  

posted @ 2016-10-14 15:50  のんきネコ  阅读(197)  评论(0编辑  收藏  举报