Skip to main content

CREATE VIEW

Create a virtual table based on a query. The view does not store data; it evaluates the underlying query each time it is referenced.

Syntax

Parameters

ParameterDescription
view_nameName of the view to create
select_statementA SELECT query that defines the view

Examples

Simple view

CREATE VIEW recent_articles AS
SELECT id, title, views, published_at
FROM articles
WHERE published_at > NOW() - INTERVAL '30 days';

View with joins

CREATE VIEW article_authors AS
SELECT a.id, a.title, au.name AS author_name
FROM articles a
JOIN authors au ON a.author_id = au.id;

See also