首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

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

2012-07-22 
删除重复数据保留id最大那条select b.id,b.usernamefrom test b where b.id not in (select max(t.id) as

删除重复数据保留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);

热点排行