Working with Database Views
A View is a virtual table containing data generated from a stored query. Views hide complex query structures and secure tables by restricting direct field access.
1 Creating & Dropping Views
SQL — View Syntax
CREATE VIEW published_posts_summary AS
SELECT posts.id, posts.title, users.username AS author_name
FROM posts
INNER JOIN users ON posts.user_id = users.id
WHERE posts.is_published = 1;
# Query the view as if it were a normal table
SELECT * FROM published_posts_summary;
2 Code Challenge
Challenge: Create a view named
expensive_products displaying only products priced above $500, showing name, price, and category properties.