What Is a SQL View?

A view is a saved, named query that behaves like a virtual table — querying it runs the underlying query fresh each time, without storing the data separately...

Published November 19, 2026

A SQL view is a saved query that behaves like a virtual table. It does not store data itself; each time you select from it, the database runs the underlying query.

The concept

Views simplify complex joins, hide columns for security and give a stable interface when tables change.

Materialised views store the results physically and must be refreshed; they trade freshness for speed.

Query behind a name

SELECT * FROM active_customers;
→ runs: SELECT id, name FROM customers WHERE status = 'active'

Practical examples

Create a view

CREATE VIEW active_customers AS
SELECT id, name, email FROM customers WHERE status = 'active';

Use like a table

SELECT name FROM active_customers WHERE email LIKE '%@example.com';

Materialised view (PostgreSQL)

CREATE MATERIALIZED VIEW daily_sales AS SELECT date(created_at) d, SUM(total) FROM orders GROUP BY 1;
REFRESH MATERIALIZED VIEW daily_sales;

Common mistakes

  • Assuming a view is faster than the query.
  • Stacking views on views until it is unreadable.
  • Forgetting to refresh materialised views.

Key takeaways

  • Saved query as a virtual table.
  • Great for simplification and access control.
  • Materialised views store results.

FAQ

Can I update through a view?

Sometimes, for simple single-table views.

View vs table?

A table stores data; a view stores a query.

More SQL articles