这个问题的目的是找出如何使用内部连接来过滤掉结果。
我有 2 个表,由一列相关。表Names
包含大约 100,000 多条记录。
Table: Names
+----+------+
| ID | Name |
+----+------+
| 1 | A100 |
| 2 | A100 |
| 3 | A100 |
| 4 | A200 |
...
Table: TableB
+----+---------------+
| ID | ChildrenCount |
+----+---------------+
| 1 | 20 |
| 2 | 25 |
| 3 | 10 |
| 4 | 70 |
...
问题 1
这些查询中哪一个更有效?
select n.[ID]
from Names n
inner join TableB b
on b.[ID] = n.[ID]
and b.[ChildrenCount] > 50
where n.[Name] Like 'A%'
或者
select n.[ID]
from Names n
inner join TableB b
on b.[ID] = n.[ID]
and b.[ChildrenCount] > 50
and n.[Name] Like 'A%'
问题2
【查询1】是where
先过滤掉子句再对结果集进行inner join,还是按顺序过滤(先inner join,后where子句)?