关于not in 和not exists
select * from t1 where c2 not in (select c2 from t2);
no rows found
诚如作者所言,使用上述语句的确返回empty,这个是null的缘故,
我用sql> select * from t1 where t1.c2 not in (select c2 from t2 where t1.c2=t2.c2);语句就可以返回正确的结果;
如果改掉null,使用select * from t1 where c2 not in (select c2 from t2); 也是可以返回正确结果的,但不能保证不存在null,所言加上t1.c2=t2.c2是保险的,
至于效率的话我这就没法知道了,毕竟数据量太少了,作者说的子查询和关联子查询的效率我就不了解了,我也是菜鸟啊。
5楼 Guanglew 2015-12-24 10:19发表 [回复]-
-
来看头像的
4楼 nightseventhunit 2015-02-03 15:26发表 [回复]-
-
哎呦,不错哦。
3楼 wangpo1988 2014-03-18 15:14发表 [回复]-
-
关于not in 和not exists
select * from t1 where c2 not in (select c2 from t2);
no rows found
诚如作者所言,使用上述语句的确返回empty,这个是null的缘故,
我用sql> select * from t1 where t1.c2 not in (select c2 from t2 where t1.c2=t2.c2);语句就可以返回正确的结果;
如果改掉null,使用select * from t1 where c2 not in (select c2 from t2); 也是可以返回正确结果的,但不能保证不存在null,所言加上t1.c2=t2.c2是保险的,
至于效率的话我这就没法知道了,毕竟数据量太少了,作者说的子查询和关联子查询的效率我就不了解了,我也是菜鸟啊。
2楼 asdvdvsdf 2014-02-20 14:26发表 [回复]-
-
好文章,谢谢
1楼 心之所求 2013-12-13 11:11发表 [回复]-
-
长知识了,对我这种菜鸟很有用