11
I have a table with a lot of data and I need to join it with some other large tables.
Only a small portion of my table is actually relevant for me each time.
When is it best to filter my data?
In the where clause of the SQL.
Create a temp table with the specific data and only then join it.
Add the predicate to the first inner join ON clause.
Some other idea.
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 …
Another question:
What happens first? Join or Where?