例如,我有這樣的查詢。通過聯接替換子查詢有意義嗎?
select col1 from t1 where col2>0 and col1 in (select col1 from t2 where col2>0)
據我瞭解,我可以通過下面的查詢替換它:
select t1.col1 from t1
join (select col1 from t2 where col2>0) as t2
on t1.col1=t2.col1
where t1.col2>0
ADDED
在一些答案我在其他inner join
看到join
。都對嗎?或者他們甚至完全相同?
我不知道MySQL ...但我非常確定`JOIN` *往往會在SQL Server和Oracle中更快。 – rsenna 2010-12-23 15:23:01
您在這裏的加入仍在使用子查詢,因此不會使其更快。 – Danosaure 2010-12-23 15:27:08
就JOIN類型而言,從內存中,我認爲JOIN相當於INNER JOIN也可以看看這裏http://www.wellho.net/mouth/158_MySQL-LEFT-JOIN-and-RIGHT-JOIN-INNER- JOIN-and-OUTER-JOIN.html – Jaydee 2010-12-23 15:39:00