题解 | #删除emp_no重复的记录#

删除emp_no重复的记录,只保留最小的id对应的记录。

https://www.nowcoder.com/practice/3d92551a6f6d4f1ebde272d20872cf05

DELETE FROM titles_test  
WHERE NOT EXISTS (  
    SELECT 1  
    FROM (  
        SELECT emp_no, MIN(ID) as min_id  
        FROM titles_test  
        GROUP BY emp_no  
    ) as subquery  
    WHERE subquery.emp_no = titles_test.emp_no AND subquery.min_id = titles_test.ID  
);

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务