Lesson 26 / 28

Views

A saved query you can select from like a table.

Creating a view

A view stores a SELECT under a name — querying it re-runs the underlying query each time.

CREATE VIEW high_value_orders AS
SELECT o.id, c.name, o.amount
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.amount > 1500;

SELECT * FROM high_value_orders;

Why use a view

Views hide complex joins behind a simple name and can restrict which columns a user is allowed to see.