select
* from
(select * from tmp group by userName having count(userName)= 1
union select * from tmp where id in ( select id from tmp group by userName having count(userName)> 1)
) aaa order by id
* from
(select * from tmp group by userName having count(userName)= 1
union select * from tmp where id in ( select id from tmp group by userName having count(userName)> 1)
) aaa order by id