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
| name | price |
|---|---|
| A5 notebook | 8.5 |
| Gel pens, pack of 10 | 11.0 |
| Green tea, 100 bags | 12.0 |
| SQL Pocket Guide | 25.0 |
| Wireless mouse | 29.0 |
5 rows
Related
Learn it step by step in the free lesson Designing a Database, with exercises that check your queries.