2

Is it possible to create a view, called first_view and in another view called second_view the first one is called? This is the original question.

This is the first view:

CREATE MATERIALIZED VIEW first_view
AS SELECT atable.variable_one, btable.another_variable, ctable.variable_x
FROM a atable, b btable, c ctable

So that f(a,b,c) view can be called in f(ALL) which is f(a,b,c) including f(m) with aggregate functions.

3
  • 2
    Yes a MVIEW can select from another MVIEW. What exactly is your problem? What is the error you get? How does the second MVIEW look like? And why aren't you not joining your tables properly? Commented May 29, 2016 at 17:04
  • @a_horse_with_no_name this was an exam question. Its theoretical so in theory, how would the joining work? These are all fictional Commented May 29, 2016 at 17:06
  • In theory, queries, views, tables, and materialised views are all relations, and should be interchangeable for DML SQL. Commented May 29, 2016 at 17:15

1 Answer 1

2

The answer is so simple that I assume that I do not understand your question properly:

Just use the first MVIEW the same way you use any other table or view in the second MVIEW:

create materialized view first_view
as
select a.column_one, b.column_two, c.column_three
from table_a a 
   join table_b b on a.id = b.aid
   join table_c c on b.id = c.bid;

create materialized view second_view
as
select x.some_column, f.*
from other_table x
   join first_view f on x.id = f.column_one;
Sign up to request clarification or add additional context in comments.

1 Comment

Oh now I understand. Thanks a lot @a_horse_with_no_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.