Reputation: 71188
I have 3 tables (A,B,C) and I need quite often to query the result of
A inner join B
union
A inner join C
I'm just thinking which way is going to be faster:
to write in each query the whole thing from scratch
to create a view and use it in queries
Upvotes: 2
Views: 329
Reputation: 134923
A view in general is nothing else but a stored version of the SQL, in that case no. However you might get some benefit by using indexed view, especially with aggregations....having said that..indexed views have a ton of restrictions...for one union
is not allowed
Upvotes: 2
Reputation: 300489
If the view contains no aggregations, then using the view will be exactly the same as using the raw SQL. No aggregations means that a where clause can be applied 'internally' to a view where the optimiser deems optimal (based on statistics). (I think this is often referred to as 'pushing' the where clause inside a view)
Upvotes: 1