View
In one line
A view is a named, saved SQL query that behaves like a virtual table — it does not store data itself.
In simple words
A view is a saved query that you can select from as if it were a table. It does not store data — instead, every time you query the view, the underlying query runs and returns current results.
Views are useful for:
- Simplifying complex queries: save a complex join as a view, then select from it.
- Security: grant access to a view that exposes only certain columns, not the whole table.
- Abstraction: if the underlying tables change, you update the view and existing queries keep working.
A CREATE VIEW statement defines the view. Some views are updatable (you can INSERT/UPDATE through them); others are read-only.
Example
sql
-- Create a view that shows active users with their order count
CREATE VIEW active_user_stats AS
SELECT u.id, u.name, COUNT(o.id) AS order_count
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.active = TRUE
GROUP BY u.id, u.name;
-- Now query it like a table
SELECT * FROM active_user_stats;The view encapsulates a complex join and aggregation. You query it as if it were a simple table.
Related terms
Related Resources
Related Lessons
- Views
Learn how to create and use views.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.