求SQL三表联合查询的语句优化

select t_cp.id,t_cp.proc, t_odid_cpid.num from t_odid_cpid,t_cp where (t_cp.id = t_odid_cpid.cpid )
and t_odid_cpid.cpid in
( select t_odid_cpid.cpid from t_odid_cpid where t_odid_cpid.odid
in (select odid from T_ORDER where B_zzdm = '785390650'))
求以上语句的优化,非常感谢

select t_cp.id, t_cp.proc, t_odid_cpid.num 

from t_odid_cpid 

left join t_cp on t_cp.id = t_odid_cpid.cpid 

left join T_ORDER on t_odid_cpid.odid = T_ORDER.odid 

Where T_ORDER.B_zzdm = '785390650'。


select t_cp.id, t_cp.proc, t_odid_cpid.num 
from t_odid_cpid 
left join t_cp on t_cp.id = t_odid_cpid.cpid 
left join T_ORDER on t_odid_cpid.odid = T_ORDER.odid 
Where T_ORDER.B_zzdm = '早春785390650'

SQL语句尽量不要用子查询,子查询腊穗速度最慢的陆局耐.


select t_cp.id,t_cp.proc, t_odid_cpid.num
from t_odid_cpid,t_cp ,T_ORDER
where t_cp.id = t_odid_cpid.cpid
and t_odid_cpid.cpid=T_ORDER.odid
and t_cp.id = T_ORDER.odid
and B_zzdm = '785390650'

语句再优化,也源消离不开索引,所以,索引雹饥知也得肢察建
select t_cp.id,t_cp.proc,t_odid_cpid.num 
from t_odid_cpid
left join t_odid_cpid
on t_cp.id=t_odid_cpid.cpid
left join T_ORDER 
on t_odid_cpid.odid=T_ORDER.odid
WHERE T_ORDER.B_zzdm = '785390650'携宴

写语句的时候尽量不要用蠢隐昌in,效率比较低,可以用exist或者join来替代,从而提高性能.

另外注意条带扒件及连表字段加上索引,也可以提高性能.