【发布时间】:2011-03-31 08:06:35
【问题描述】:
我有一个包含大量数据的表,我需要将它与其他一些大表连接起来。
每次我的表中只有一小部分与我真正相关。
什么时候最好过滤我的数据?
在 SQL 的 where 子句中。
使用特定数据创建一个临时表,然后才加入它。
将谓词添加到第一个内连接 ON 子句。
其他想法。
1.
Select *
From RealyBigTable
Inner Join AnotherBigTable On …
Inner Join YetAnotherBigTable On …
Where RealyBigTable.Type = ?
2.
Select *
Into #temp
From RealyBigTable
Where RealyBigTable.Type = ?
Select *
From #temp
Inner Join AnotherBigTable On …
Inner Join YetAnotherBigTable On …
3.
Select *
From RealyBigTable
Inner Join AnotherBigTable On RealyBigTable.type = ? And …
Inner Join YetAnotherBigTable On …
另一个问题:
首先会发生什么? Join 或 Where?
【问题讨论】:
标签: sql sql-server performance