Define a reusable read-only query projection.
Section: Create reusable views
Create a view
sql
sql
CREATE VIEW recent_posts AS
SELECT p.id, p.title, u.email AS author_email, p.created_at
FROM posts p
JOIN users u ON u.id = p.user_id
WHERE p.created_at >= date('now', '-30 day');Explanation
Views are great for simplifying repeated report queries or exposing app-friendly shapes.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Create reusable views
Create an AFTER INSERT trigger
Write to an audit log when a row is created.
Normalize data with a generated column
Compute a lowercased email for indexing or search.