mysql - SQL : Select row where a column of this row does't match with a certain value

标签 mysql select

我有一个表,例如,一个列 id_type 和另一个列 num_area。我想搜索 num_area 的值与特定值不匹配的所有 id_type。

id_type    num_area 
----        ----   
1           121
2           121
1            95
3            47
4            65

例如,如果我想要没有 num_area 121 的 id_type,它会返回我,id_type 3 和 4。

谢谢

最佳答案

计划

  • list id_type where num_area is 121
  • list distinct id_type not in above

查询

select distinct id_type
from example
where id_type not in
(
  select id_type
  from example
  where num_area = 121
)
;

输出

+---------+
| id_type |
+---------+
|       3 |
|       4 |
+---------+

sqlfiddle

关于mysql - SQL : Select row where a column of this row does't match with a certain value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32818991/

相关文章:

mysql - 数据库 - 以 VARCHAR 数据类型存储数值

c++ - 在 C++ 项目中静态链接 MySQL (Mac OS X, g++, Eclipse)

css - Angular Material 选择选项宽度?

mysql : how to add a where clause superior on text

php - 输出中的重复记录

mysql - 从另一个表中选择具有备用有序字段的行

mysql - 计算 ORDER BY 之后的记录

mysql按子查询结果过滤

sql - SQLITE3子查询

Mysql向插入中跳过的cols添加NULL并且该col是唯一的