0
mysql> select * from table3 order by id;
+------+-------+
| id   | value |
+------+-------+
|    1 | a     |
|    1 | b     |
|    1 | c     |
|    1 | d     |
|    2 | a     |
|    2 | b     |
|    3 | a     |
|    3 | b     |
|    3 | c     |
|    4 | a     |
|    4 | b     |
+------+-------+

値 'c' を持たないすべての IDを選択したかったのです。

次のクエリでは単純に機能しません。

mysql> select distinct id from table3 where value <> 'c';
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
|    4 |
+------+

必要なのは2 と 4 のリターンだけです。

ご清聴ありがとうございました!

4

2 に答える 2

2

これはあなたのために働くでしょう

select distinct id from table3 where 
             id not in ( select id from table3 where value = 'c')
于 2012-11-16T06:45:28.960 に答える
1
select distinct id 
from table3 t
where not exists 
                 (select 1 from table3 where value = 'c' and id = t.id)
于 2012-11-16T06:45:55.900 に答える