---
title: "sql去除重复记录"
author: "zero1111"
date: "2015-03-12T15:02:20Z"
tags: []
categories: ["数据库"]
slug: "sql"
draft: false
lastmod: "2015-03-12T15:02:20Z"
id: 2191800
url: "https://zero1111.iteye.com/blog/2191800"
---

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