Plain Views: Logical Reuse
Create views to encapsulate complex queries, simplify reports, and give read access to a subset of columns.
What Is a View?
A view is a saved SELECT. Every time you query the view, the underlying SELECT runs. Like a named query you can JOIN, filter, and aggregate over.
CREATE VIEW active_users AS
SELECT id, email, full_name
FROM users
WHERE deleted_at IS NULL;Using a View
Query it like any table:
SELECT COUNT(*) FROM active_users;
SELECT * FROM active_users WHERE email LIKE '%@gmail.com';All lessons in this course
- Plain Views: Logical Reuse
- Updatable Views and INSTEAD OF Triggers
- Materialized Views and REFRESH Strategies
- When to Pre-Aggregate