日期:2014-05-17  浏览次数:20380 次

求救一条删除重复的sql语句

SELECT *
FROM User_Property a
WHERE  ((SELECT COUNT(property_mall_ID)
FROM User_Property
WHERE property_mall_ID=a.property_mall_ID and  User_Property_UserName = a.User_Property_UserName)>1 )
ORDER BY User_Property_UserName DESC


我这里面查询出来的,都是property_mall_ID重复的记录
比如
ID   username   property_mall_ID
1     aaaa       1
2     aaaa       1
3     aaaa       2
4     aaaa       2
5     bbbb       1
6     bbbb       1
7     cccc       5
8     cccc       5
.......

我需要一条sql语句,删除重复的,保留ID为最小的一条记录(表里面有几万条数据)

删除后的记录为
ID   username   property_mall_ID
1     aaaa       1
3     aaaa       2
5     bbbb       1
7     cccc       5
.....

求哪位大侠Help一下
sql

------解决方案--------------------


delete from User_Property where  id in
(
select id from
(
(
SELECT     dense_rank() OVER (partition BY username+property_mall_ID   ORDER BY property_mall_ID
 ASC) AS AId,id from User_Property 

) t where t.aid<>1
)



手写的 不知道可以不可以 你先备份下表 在 执行  免得弄错了.
------解决方案--------------------
一楼正确答案。。。
------解决方案--------------------
引用:
有哪位大神指导一下、、、、、



delete from ax
 where id 
------解决方案--------------------
 username 
------解决方案--------------------
 property_mall_id in
       (select id 
------解决方案--------------------
 username 
------解决方案--------------------
 property_mall_id
          from (select id,
                       username,