January 2016
Intermediate to advanced
240 pages
7h 36m
English
Materialized views are a special form of database view that performs much better. If you aren’t familiar with views, they are a table-like construct that abstracts away a complex query. For example, we could create a view named ADDRESSES_WITH_STATES that abstracts away the need to join ADDRESSES and STATES together, like so:
| | CREATE VIEW addresses_with_states AS |
| | SELECT |
| | addresses.id, |
| | addresses.street, |
| | addresses.city, |
| | states.code AS state, |
| | addresses.zipcode |
| | FROM |
| | addresses |
| | JOIN states ON states.id = addresses.state_id; |
Now, we can treat ADDRESSES_WITH_STATES just like a normal table for querying:
| | sql> select * from addresses_with_states |
Read now
Unlock full access