Question
What is view and materialized view ? What is the difference?
A
Anonymous
January 6, 2026
89
Answer
View:
A view is a virtual table based on a SQL query.
- It does not store data physically.
- Every time you query a view, the database re-runs the underlying SELECT query to fetch the latest data.
- Think of it as a saved query that behaves like a table.
Example: Creating a View
CREATE VIEW employee_salaries AS
SELECT emp_id, first_name, last_name, salary
FROM employees
WHERE active = 1;
Materialized View
A materialized view is a physical copy of the result of a SQL query.
- It stores data on disk.
- It must be refreshed (manually or automatically) to update its data.
- It is used to speed up performance, especially for heavy queries.
Example : Create a Materialized View
CREATE MATERIALIZED VIEW sales_summary AS
SELECT product_id, SUM(amount) AS total_sales
FROM sales
GROUP BY product_id;
Quick Memory Trick
- View = Live data (always fresh, but slower).
- Materialized View = Stored snapshot (faster, but may be outdated).
SeniorJuniorDatabase
Loading comments...