Querying from Views in MySQL
📖 Scenario: You work at a bookstore that keeps track of books and their sales. You want to create a simple way to see the total sales for each book without writing complex queries every time.
🎯 Goal: Create a view that shows each book's title and total sales, then write a query to get all data from this view.
📋 What You'll Learn
Create a table called
books with columns book_id (integer), title (varchar), and price (decimal).Create a table called
sales with columns sale_id (integer), book_id (integer), and quantity (integer).Create a view called
book_sales_view that shows title and total sales amount (price * quantity) as total_sales.Write a query to select all columns from
book_sales_view.💡 Why This Matters
🌍 Real World
Views help simplify repeated complex queries in business reporting, making it easier to get summarized data quickly.
💼 Career
Database developers and analysts use views to create reusable query layers that improve efficiency and maintainability.
Progress0 / 4 steps