具有多个联接的SQL Server查询

时间:2018-02-13 16:46:03

标签: sql-server

我有一个使用多个连接构建的查询。我想知道哪一个是下面2之间的最佳实践(最快)。它们都返回相同的结果。谢谢

SELECT A.ID FROM RE7.DBO.RECORDS AS A
LEFT OUTER JOIN [re7].[dbo].[ADDRESS] AS B ON A.ID=B.ID 
WHERE B.COUNTRY = 1670

SELECT A.ID FROM RE7.DBO.RECORDS AS A
INNER JOIN (SELECT ID FROM [re7].[dbo].[ADDRESS] WHERE COUNTRY = 1670) AS B
ON A.ID=B.ID

1 个答案:

答案 0 :(得分:0)

SELECT A.ID FROM RE7.DBO.RECORDS AS A
INNER JOIN (SELECT ID FROM [re7].[dbo].[ADDRESS] WHERE COUNTRY = 1670) AS B
ON A.ID=B.ID

INNER JOINS几乎总是比LEFT OUTER JOIN快。 LEFT OUTER JOIN占所有联接中最长的。

在这种情况下,您可能看不到查询时间的巨大差异,但INNER JOINS是最佳做法。