Does it make a difference if you filter a View inside or outside the View?
For example, is there any difference between these two queries?
SELECT Id
FROM MyTable
WHERE SomeColumn = 1
Or
SELECT Id
FROM MyView
WHERE SomeColumn = 1
And MyView
is defined as
SELECT Id, SomeColumn
FROM MyTable
And is the answer any different if the source table is located on a Linked Server?
I'm asking because I have to query a large table (44mil rows) twice from a linked server, and get an aggregate of the results. I want to know if I should create two views to access the data, one for each query, or if I can get away with a single view and a WHERE
clause.
UNION ALL
. It's much easier to use a View than to have to rewrite the UNION query anytime I need the data.