Create a Simple View in PostgreSQL
📖 Scenario: You work in a small bookstore. You have a table that stores information about books, including their title, author, and price. You want to create a view that shows only the books that cost more than $20, so your coworkers can quickly see the expensive books without looking at the full table.
🎯 Goal: Create a view named expensive_books that shows the title, author, and price of books costing more than 20 dollars from the books table.
📋 What You'll Learn
Create a table named
books with columns id (integer), title (text), author (text), and price (numeric).Insert exactly three rows into the
books table with the following data: (1, 'The Great Gatsby', 'F. Scott Fitzgerald', 10.99), (2, 'War and Peace', 'Leo Tolstoy', 25.50), (3, 'Ulysses', 'James Joyce', 30.00).Create a numeric variable
price_threshold and set it to 20.Create a view named
expensive_books that selects title, author, and price from books where price is greater than price_threshold.💡 Why This Matters
🌍 Real World
Views help you save complex queries and share filtered or summarized data easily with coworkers or applications.
💼 Career
Database views are commonly used in jobs to simplify data access, improve security by limiting columns or rows, and organize data for reports.
Progress0 / 4 steps