2017-04-13 38 views
0

我不明白這一點。從幾張表VS內部加入

是什麼

select e.empid 
from employee_table e 
inner join customer_table c 
on deref(c.infos).personid = deref(e.infos).personid 
order by e.empid; 

select e.empid 
from employee_table e, customer_table c 
where deref(c.infos).personid = deref(e.infos).personid 
order by e.empid; 

的結果是相差無幾。 比其他人快嗎?

何時使用內部聯接時,我們可以簡單地從多個表中選擇?

回答

1

因爲這兩個查詢是等價的。但第一個使用ANSI-92樣式的連接,第二個使用ANSI-89樣式的連接。較新的連接語法不太容易出錯,現在已經有25年了。

您應該始終使用ANSI-92樣式的連接。 http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style-joins.aspx

+0

我編輯了e.supervisor的帖子。謝謝你的建議。它在sql引擎中的運行是否相同? –

+0

嗯,我不知道哪個sql引擎,但這些是ANSI標準,幾乎每個DBMS都非常接近。當然,加入所有主要的將是相同的。 –