日期:2014-05-19  浏览次数:20587 次

问个效率高点的SQL语句
现在A表B表2张表
要从B表中取值
满足B表中b6列的值为A表中a1=5的记录中的a6的值
谢谢
效率要高一些的。

------解决方案--------------------
select b.* from a,b where a.a6=b.a6 and a1=5 ?
------解决方案--------------------
我晕,这个也效率低?ft
select b.* from a,b where a.a6=b.a6 and a1=5
------解决方案--------------------
select b.* from a inner join b on a.a6=b.a6 and a1=5
------解决方案--------------------
select b.* from b left join a on b.b6 = a.a6 where a.a1 = 5;
------解决方案--------------------
select b.* from b
where exists (select * from a where a.a6=b.b6 and a1=5)

這種寫法需要的時間最少,建立的臨時視圖最小。
------解决方案--------------------
select b.* from b
where exists (select * from a where a.a6=b.b6 and a1=5)

這種寫法需要的時間最少,建立的臨時視圖最小。

我不 认为 時間最少
------解决方案--------------------
select b.* from a, (select distinct a6 from b where a1=5) as c where a.a6=c.a6

我 猜得 没试过
------解决方案--------------------
select b.* from b, (select distinct a6 from a where a1=5) as c where b.a6=c.a6

我 猜得 没试过

------解决方案--------------------
select b.* from b
where exists (select 1 from a where a.a6=b.b6 and a1=5)

------解决方案--------------------
exists 应该是最快的了