`
joe_zhjiang
  • 浏览: 155867 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

删除重复数据保留id最大那条

 
阅读更多
select b.id,b.username
  from test b
 where b.id not in (select max(t.id) as id
                      from test t
                    having count(t.username) > 1
                     group by t.username)
   and b.username in (select t.username
                  from test t
                having count(t.username) > 1
                 group by t.username);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics