A view is a saved query that behaves like a virtual table — useful for hiding complex joins behind a simple name, or for restricting what a given user can see without duplicating data.
CREATE VIEW active_customers AS SELECT c.id, c.email, COUNT(o.id) AS order_count, SUM(o.total) AS lifetime_value FROM customers c JOIN orders o ON o.customer_id = c.id WHERE o.status != 'cancelled' GROUP BY c.id, c.email; -- Query it exactly like a table SELECT * FROM active_customers WHERE lifetime_value > 500;
Views Aren’t Free Performance
A view doesn’t cache anything by default — every query against it re-runs the underlying SQL. For genuinely expensive aggregations queried often, a materialized approach (a real summary table refreshed periodically) performs far better than a plain view.