---
title: "查出数据库中多个字段相同的行"
author: "oyprunner"
date: "2010-02-08T14:56:55Z"
tags: ["C", "C#", "C++", "SQL"]
categories: ["数据库"]
slug: "untitled"
draft: false
lastmod: "2010-02-08T15:11:15Z"
id: 591450
url: "https://oyprunner.iteye.com/blog/591450"
---

刚开始表没有设置主键盘，后来要设置 多个字段作为主键 但是这几个字段的值有少部门是重复的，
所以要找出重复的行。


```sql
三个设置为主键的字段：c_year，c_parent，c_name
--找出重复的行
select *
  from t_qq9_gdp t
 where
 rowid != (select max(rowid)
             from t_qq9_gdp t2
            where t.c_year = t2.c_year
              and t.c_parent = t2.c_parent
              and t.c_name = t2.c_name);
--选出重复的行              
select *
  from t_qq9_gdp t
 where t.c_year = '2002'
   and t.c_parent = '拉丁美洲和加勒比海地区'
   and (t.c_name = '多米尼加共和国' or t.c_name = '危地马拉');
```



```sql

select c_nme,count(*) as aa from tb_user_info t
group by c_nme,c_pwd,c_enabled
order by aa desc

```

注意是group by  不是order by