2011-09-26 33 views
3

可能重複:
which query is better and efficient - mysql這些MySQL SELECT查詢是否表示不同的內部連接?

有什麼區別,如果有的話,這兩個(MySQL的)之間的SELECT查詢?

SELECT name, salary 
FROM employee, info 
WHERE employee.id = info.id; 

SELECT e.name AS name, i.salary AS salary 
FROM employee AS e 
INNER JOIN info AS i 
ON e.id = i.id; 

兩者表示(在同一?)內加入對錶employeeinfo

+2

您可以找到關於此主題的許多討論:http://stackoverflow.com/questions/3138742/which-query-is-better-and-efficient-mysql/3138863 –

+0

大!謝謝 – waanders

+0

是重複的,我也發現這個:http://stackoverflow.com/questions/1018822/inner-join-versus-where-clause-any-difference。對不起 – waanders

回答

1

是的兩者都代表INNER JOIN

SELECT e.name AS name, i.salary AS salary 
FROM employee AS e 
INNER JOIN info AS i 
ON e.id = i.id; 

"explicit join notation"使用JOIN關鍵字來指定要連接的表,和ON關鍵字指定謂詞的加入。

SELECT name, salary 
FROM employee, info 
WHERE employee.id = info.id; 

"implicit join notation"簡單地列出了連接表(在SELECT語句的條款),用逗號將它們分開。因此,它指定了cross join,並且WHERE子句可能會應用其他過濾謂詞(與顯式表示法中的連接謂詞相當)。

看看這個例子:http://en.wikipedia.org/wiki/Join_%28SQL%29#Inner_join

+1

只需注意:在MySQL中'交叉連接'和'內部連接'是同義詞。 – Karolis