框起来的部分时重复的记录,如何使用sql语句删除任意一条重复的记录
4条回答 默认 最新
- PHP技术栈 2021-10-21 20:24关注
设表名为:test_user
DELETE FROM test_user WHERE(type_user,user_u_id,gtrevuser_id)
IN(SELECT type_user,user_u_id,gtrevuser_id FROM(SELECT type_user,user_u_id,gtrevuser_id FROM test_user GROUP BY type_user,user_u_id,gtrevuser_id HAVING count() > 1) AS A)
AND id NOT IN(SELECT id FROM(SELECT min(id) AS id FROM test_user GROUP BY type_user,user_u_id,gtrevuser_id HAVING count()>1) AS B)DELETE FROM test_user WHERE(type_user,user_u_id,gtrevuser_id) IN(SELECT type_user,user_u_id,gtrevuser_id FROM(SELECT type_user,user_u_id,gtrevuser_id FROM test_user GROUP BY type_user,user_u_id,gtrevuser_id HAVING count() > 1) AS A) AND id NOT IN(SELECT id FROM(SELECT min(id) AS id FROM test_user GROUP BY type_user,user_u_id,gtrevuser_id HAVING count()>1) AS B)
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报