alias,exist以及in的使用
==============================
1、使用别名
在进行多表连接的时候,如果连接的层次过多
可以使用别名来代替表名,这样可以
减少解析时间
减少字段模糊引用的错误
----------------------
exist以及in的使用
SQL> select count(*) from an where an.id in (select an.id from an);
COUNT(*)
----------
20000
已用时间: 00: 00: 00.11
SQL> select count(*) from an where exists (select an.id from an);
COUNT(*)
----------
20000
已用时间: 00: 00: 00.01
通过上面的实验,证明在查询的时候,使用exists能快些
对not in和not exists的情况也基本相同
但实际工作中我的经验是
当右边的数据量相对较少的时候,使用in快些
右边数据量相对较大的时候,使用exists快些
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/13177610/viewspace-676341/ ,如需转载,请注明出处,否则将追究法律责任。