为质量而战!为胜利而战!

更高效的SQL使用技巧

上一篇 / 下一篇  2009-06-16 09:33:03 / 个人分类:Oracle和DB2

1、最后指定最大的表
from a,b,c
数据量:a<b<c

2、使用外连接而不是union

3、在子查询中,无需使用distinct

select a from table where a in (selectdistinctA from table2)

4、使用between来代替 >and<
and a.createTime >= '2008-10-01'
 and a.createTime <= '2009-10-01'


5、避免使用not运算符
state not in ( '1' , '3')
可改成state in ('2' , '4' , '5')    //前提是state的值为1、2、3、4、5中的任何一个

6、避免使用or运算符
用in代替:a=1 or a=2
用union代替a=1 or b='tom'


TAG: distinct union 高效SQL

 

评分:0

我来说两句

日历

« 2024-04-14  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 50134
  • 日志数: 64
  • 文件数: 1
  • 书签数: 1
  • 建立时间: 2008-03-28
  • 更新时间: 2009-08-14

RSS订阅

Open Toolbar