Lesson 27 / 30

Views

Save a SELECT as a view to hide complex joins and limit which columns users can see.

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.