sql236

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

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

delete from
    titles_test
where
    titles_test.id not in (
        select
            t.minid
        from
            (
                select
                    min(id) minid
                from
                    titles_test
                group by
                    emp_no
            ) as t
    )

知识点 delete + where 可删除指定行

但要遵循mysql运行逻辑,假设要更新的表是A,不可以引用A的元素来更新A。

否则会报错:You can't specify target table 'CUP_TEST_CLASS_LIST' for update in FROM clause

解决方法:利用子查询创立一个派生表过渡即可

全部评论

相关推荐

牛至超人:您好,京东物流岗了解一下吗?负责精加工食品的端到端传输
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务