请教下面两个sql的差别
select t1.id2, t1.id3, t2.name, t3.name
from t1, t2, t3
where t1.id2 = t2.id2 and t1.id3 = t3.id3;
select t1.id2, t1.id3,
(select name from t2 where t1.id2=t2.id2),
(select name from t3 where t1.id3=t3.id3)
from t1;
这两个sql有什么差别,主要是效率上,其余各个方面如果有的话也都要,谢谢
------解决方案--------------------第一个是一个查询
后一个是三个查询
个人认为是第一个要快些
------解决方案--------------------看了执行计划
select t1.id2, t1.id3, t2.name, t3.name
from t1, t2, t3
where t1.id2 = t2.id2 and t1.id3 = t3.id3;的效率应该高一些
------解决方案--------------------第一个比较快,有了子查询,效率都会降低的
------解决方案--------------------explain一下,什么都明了了
------解决方案--------------------EXPLAIN EXTENDED select t1.id2, t1.id3, t2.name, t3.name
from t1, t2, t3
where t1.id2 = t2.id2 and t1.id3 = t3.id3;
EXPLAIN EXTENDED select t1.id2, t1.id3,
(select name from t2 where t1.id2=t2.id2),
(select name from t3 where t1.id3=t3.id3)
from t1;