select * from t1 left join t2 on t2.sysno =t1.ASysNo left join t3 on t3.sysno =t2.ASysNo left join t4 on t4.sysno =t3.ASysNo left join t5 on t5.sysno =t4.ASysNo left join t6 on t6.sysno =t5.ASysNo left join t7 on t7.sysno =t6.ASysNo where t1.name like '%AAA%'
在没有建任何索引的情况下,模糊查询,这类sql性能最差,这类SQL为联合查询SQL
select * from t1 left join ( select * from t2 left join t3 on t3.sysno =t2.ASysNo left join t4 on t4.sysno =t3.ASysNo ) vw_detail on vw_detail .sysno =t1.ASysNo left join ( select * from t5 left join t6 on t6.sysno =t5.ASysNo left join t7 on t7.sysno =t6.ASysNo ) vw_mm on vw_mm.sysno = t1.SSysNo where charindex('AAA',t1.name)>0
将SQL用left-join把一类的数据包起来分类关联,去掉like查询,尽量减少where中使用函数,然后对各个表的外键建立索引;按照常理来说;这类SQL查询个人称为联合分类查询SQL,一般按照该规则查询后查询应该很快了
以上SQL仅供参考