日期:2014-05-16 浏览次数:20918 次
mysql> select * from woaiyingyu321;
+----+------+--------+
| id | a    | b      |
+----+------+--------+
|  1 | a    | 111111 |
|  2 | b    | 111111 |
|  3 | c    | 222222 |
|  4 | d    | 222222 |
|  5 | a    | 111111 |
|  6 | c    | 111111 |
|  7 | f    | 111111 |
|  8 | a    | 222222 |
|  9 | c    | 222222 |
| 10 | f    | 333333 |
| 11 | a    | 222222 |
| 12 | a    | 444444 |
+----+------+--------+
12 rows in set (0.04 sec)
mysql> select *
    -> from woaiyingyu321
    -> where (a,b) in (select a,b from woaiyingyu321 group by b);
+----+------+--------+
| id | a    | b      |
+----+------+--------+
|  1 | a    | 111111 |
|  3 | c    | 222222 |
|  5 | a    | 111111 |
|  9 | c    | 222222 |
| 10 | f    | 333333 |
| 12 | a    | 444444 |
+----+------+--------+
6 rows in set (0.10 sec)
mysql>