Home / SQL / Reference / Tables and design

SQL CREATE VIEW

Save a query under a name and use it like a table.

Syntax

CREATE VIEW name AS SELECT …;

A view stores no data; its query runs each time it is used.

Example

Query (on the shop database used in the SQL course)

CREATE VIEW cheap_products AS SELECT name, price FROM products WHERE price < 30;
SELECT * FROM cheap_products ORDER BY price;

Result

nameprice
A5 notebook8.5
Gel pens, pack of 1011.0
Green tea, 100 bags12.0
SQL Pocket Guide25.0
Wireless mouse29.0

5 rows

Related

Learn it step by step in the free lesson Designing a Database, with exercises that check your queries.