View (SQL)

A view is a saved SELECT query that you can treat like a virtual table. It doesn't store data itself, but shows the result of its query whenever you read from it.

SQL

Views simplify complex queries by giving them a name: instead of rewriting a big join every time, you create a view once and then SELECT from it like a normal table.

They are also useful for security and consistency — you can expose a view that hides sensitive columns while everyone reads from the same trusted definition.

Syntax

CREATE VIEW view_name AS
SELECT columns FROM table_name WHERE condition;

Examples

SQL

CREATE VIEW adults AS
SELECT name, age FROM users WHERE age >= 18;

SELECT * FROM adults;

Output:

name   age
-----  ---
Alice  30
Bob    22

Learn it in a lesson

See also

Back to the Dictionary