Views
Views allow the user to create a simpler version of a given SQL statement.
It is a logical table based on one table. A view contains no data by itself.
For example, you can change the names of the selected columns or the order of the columns.
You can also filter the result of a select SQL statement on a table.
Command
CREATE VIEW
CREATE VIEW my_view (new_name1, new_name2)
as SELECT column1, column3 FROM my_table
This will create a View named "my_view" with 2 columns: new_name_1 and new_name_2. These columns are based on the columns column1 and column3 of the table default.my_table.
Usage
From our example above, let's say that the table default.my_table is a 5 columns Fact table as follows:
column1 | column2 | column3 | column4 | column5 |
---|---|---|---|---|
BIGINT | INT | STRING | STRING | DATE |
The View named "my_view" that we created will be a logical table (there is no real data in that table) that looks like:
new_name1 | new_name2 |
---|---|
BIGINT | STRING |
You can then make queries such as
SELECT FROM VIEW
SELECT * FROM my_view
This will returns all the data from the columns column1 and column3 of my_table.
More
You can learn more about the CREATE VIEW commands here