Assigning variables to multiple select commands

Viewed 31

I have create a bunch of view tables which involves merging/joining to ultimately create one combined/merged table. I don't want to keep all of these intermediate tables in the database, is there a way to assign a variable to these intermediate view tables (table 1,table2, etc.) I created? Given example with "Combined_table" as the final output:

CREATE or REPLACE VIEW database.table1
as select ... from...left join on...;

CREATE or REPLACE VIEW database.table2
as select ...from database.table1...left join on...;

CREATE or REPLACE VIEW database.table3
as select ...from database.table1...left join on...;

CREATE or REPLACE VIEW database.Combined_table
as select
table2.field1
table2.field2
table3.field1
from database.table4
left join table2 on...
left join table3 on...

Hopefully you get the idea.

1 Answers

No automatic way.

You can of course fashion a SELECT query that is the combination of the queries you used for the other views, but it's up to you to write that full query to define the combined view. In other words, there's no "flatten" operation to transform a view-of-a-view into a view-of-the-base-query automatically.

Related