表内容如:
 id   name
 1    AAA
 2    AAA
 3    BBB
 4    CCC
 5    BBB希望取出
 id   name
 1    AAA
 2    AAA
 3    BBB
 5    BBB就是希望不要取出仅仅现过一次的CCC这一行。
谢谢!

解决方案 »

  1.   

    select * from a join (select name from a group by name having count(*) > 1) as b on  a.name = b.name
      

  2.   

    mysql> create table t1
        -> (
        -> id int not null auto_increment primary key,
        -> name char(3)
        -> );
    Query OK, 0 rows affected (0.08 sec)mysql> insert into t1 (name) values
        -> ('AAA'),('AAA'),('BBB'),('CCC'),('BBB');
    Query OK, 5 rows affected (0.06 sec)
    Records: 5  Duplicates: 0  Warnings: 0mysql> select * from t1;
    +----+------+
    | id | name |
    +----+------+
    |  1 | AAA  |
    |  2 | AAA  |
    |  3 | BBB  |
    |  4 | CCC  |
    |  5 | BBB  |
    +----+------+
    5 rows in set (0.02 sec)mysql> select * from t1 group by name having count(name) >1;
    +----+------+
    | id | name |
    +----+------+
    |  1 | AAA  |
    |  3 | BBB  |
    +----+------+
    2 rows in set (0.00 sec)
      

  3.   

    select * from a where id in (select id from a group by name having count(*) > 1)
      

  4.   

    select * from tt where t not in (select t from tt group by t2 having count(*) = 1)