MySQL中,not in子查询
来源:互联网 发布:java项目打jar 编辑:程序博客网 时间:2024/06/10 02:26
今天写sql语句的时候,希望通过not in子查询来限制查询结果,实际SQL语句如下:
select ID as id, TYPE_CODE as typeCode , TYPE_NAME as typeName ,
PARENT_ID as parentsId , STYLE as style , LEVELS as levels
from type_code
where PARENT_ID = '30119a0e-2f57-473d-9f1d-2843561e9064' and ID not in
( select PARENT_ID from type_code where PARENT_ID);
结果满足查询的条件为空……
后来发现,子查询中存在字段的某些值为null,所以导致了count=0.
所以,将SQL调整为如下:
select ID as id, TYPE_CODE as typeCode , TYPE_NAME as typeName ,
PARENT_ID as parentsId , STYLE as style , LEVELS as levels
from type_code
where PARENT_ID = '30119a0e-2f57-473d-9f1d-2843561e9064' and ID not in
( select PARENT_ID from type_code where PARENT_ID is not null);
这样就能正确的查出结果了!
总结:MySQL中如果要用not in在子查询中限制结果,那必须要将子查询的结果集限制为不含null,不然查询结果count = 0.
Allen
2011-03-29
- MySQL中,not in子查询
- mysql not in null 子查询问题
- (NOT) IN 子查询
- mysql中IN子查询排序
- Mysql子查询IN中使用LIMIT
- mysql中in子查询效率优化
- Mysql中IN子查询带有limit
- SQLServer中in和not in子查询注意事项
- mysql not in子查询返回结果为空
- MySQL IN子查询
- oracle not in 子查询中不能有空值
- SQL中带有NOT IN 子查询改写
- 41.笔记 MySQL学习——IN和NOT IN子查询
- IN+子查询(Mysql)
- mysql in() 子查询 优化
- IN&EXISTS 与 NOT IN&NOT EXISTS 子查询 区别
- SQL 中IN、NOT IN 对结果含NULL的子查询使用
- mysql子查询 -exists,not exists
- android锁屏实现思路
- 买笔记本要注意什么呢?
- 为什么如此不文明
- Android 根文件系统启动分析
- 解决android自定义标题栏充满的问题
- MySQL中,not in子查询
- Android获取其他包的Context实例然后干坏事
- MYSQL外键
- linux下用adb连接手机的问题解决
- Android自由选择TextView的文字
- Linux 下Tomcat 的安装
- Android中用AsyncTask简单实现多线程
- 我的梦想是什么
- Ubuntu下不能make menuconfig