SQL View
A view is a virtual table defined by a saved SQL query. It does not store data itself; each time you select from the view, the database runs the underlying query and returns the result as if it were a table.
Views simplify complex queries, such as joins across several tables, into one name; hide columns users should not see, such as salaries; and give applications a stable interface even when the tables underneath change. A materialized view, supported by PostgreSQL and Oracle, stores the query result physically and must be refreshed to show new data.
CREATE VIEW active_customers AS
SELECT c.id, c.name, COUNT(o.id) AS order_count
FROM customers c
JOIN orders o ON o.customer_id = c.id
WHERE c.status = 'active'
GROUP BY c.id, c.name;
SELECT * FROM active_customers WHERE order_count > 5;