#####查询重复数据 SELECT t.* FROM like_user t, ( SELECT user_id, COUNT(user_id), dynamc_id, COUNT(dynamc_id) FROM like_user GROUP BY user_id, dynamc_id HAVING (COUNT(user_id) > 1) AND (COUNT(dynamc_id) > 1) ) a WHERE t.user_id=a.user_id AND t.dynamc_id=a.dynamc_id #####删除查询到重复的数据,保留最小的id DELETE FROM like_user WHERE id in ( SELECT b.id FROM ( SELECT t.* FROM like_user t, ( SELECT user_id, COUNT(user_id), dynamc_id, COUNT(dynamc_id) FROM like_user GROUP BY user_id, dynamc_id HAVING (COUNT(user_id) > 1) AND (COUNT(dynamc_id) > 1) ) a WHERE t.user_id=a.user_id AND t.dynamc_id=a.dynamc_id ) b WHERE b.id NOT IN ( SELECT min(id) as id FROM ( SELECT t.* FROM like_user t, ( SELECT user_id, COUNT(user_id), dynamc_id, COUNT(dynamc_id) FROM like_user GROUP BY user_id, dynamc_id HAVING (COUNT(user_id) > 1) AND (COUNT(dynamc_id) > 1) ) a WHERE t.user_id=a.user_id AND t.dynamc_id=a.dynamc_id )a GROUP BY a.user_id,a.dynamc_id ) )