Mysql 如何为此编写sql查询:

Mysql 如何为此编写sql查询:,mysql,sql,tsql,Mysql,Sql,Tsql,我想选择所有没有值“c”的ID 它不会简单地通过以下查询工作: mysql> select * from table3 order by id; +------+-------+ | id | value | +------+-------+ | 1 | a | | 1 | b | | 1 | c | | 1 | d | | 2 | a | | 2 | b | | 3 | a | |

我想选择所有没有值“c”的ID

它不会简单地通过以下查询工作:

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     |
+------+-------+
mysql>从表3中选择不同的id,其中值为'c';
+------+
|身份证|
+------+
|    1 |
|    2 |
|    3 |
|    4 |
+------+
我只需要返回2和4

谢谢你的关注

这对你有用

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

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

是的,实际表格有10000多行,如果没有找到更合适的答案,我会在以后标记你的答案,谢谢是的,实际表格有10000多行,如果没有找到更合适的答案,我会在以后标记你的答案,谢谢
select distinct id 
from table3 t
where not exists 
                 (select 1 from table3 where value = 'c' and id = t.id)