What is a view in SQL?
A view is a saved query that behaves like a virtual table. It does not store data itself but shows the result of its underlying query whenever you use it. Views help by simplifying complex queries, giving a consistent interface, and hiding sensitive columns from certain users.
- A view is a saved query that behaves like a virtual table.
- It does not store data itself but shows data from underlying tables.
- Views simplify complex queries and can restrict which columns users see.
Why views are useful
- Simplify: wrap a complex join into a simple name you can query.
- Security: expose only certain columns and hide the rest.
- Consistency: everyone uses the same defined logic.
CREATE VIEW active_customers AS
SELECT id, name FROM customers WHERE active = 1;
SELECT * FROM active_customers; -- query it like a table
Because a view runs its query each time, its data is always current with the underlying tables, though this also means it does not speed up the query by itself.
If asked about performance, note that a normal view does not store data, so it does not speed queries up. Mentioning materialised views, which do store results for speed, shows deeper knowledge.
Frequently asked questions
Can you update data through a view?
Sometimes. Simple views on one table are often updatable, but views with joins, grouping, or aggregates usually are not.
What is a materialised view?
It is a view that stores its result physically and refreshes periodically, which speeds up reads at the cost of storage and freshness.
Common follow up questions
Related interview questions
Want the full SQL guide?
Read every SQL concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the SQL guide All SQL questions