SQL View Interactive Demo

Master SQL Views with Fullstackgadaโ€™s fun approach!

๐Ÿ“Š Orders Table
ID Customer ID Product ID Quantity Date
1 101 201 2 2024-01-15
2 102 202 1 2024-01-16
3 101 203 3 2024-01-17
๐Ÿ‘ฅ Customers Table
ID Name City Email Phone
101 Ram Sharma Mumbai ram@email.com 9876543210
102 Shyam Gupta Delhi shyam@email.com 9876543211
103 Geeta Patel Pune geeta@email.com 9876543212
๐Ÿ“ฆ Products Table
ID Name Price ($) Category Stock
201 Laptop 500 Electronics 25
202 Mobile 200 Electronics 50
203 Headphones 25 Electronics 100
๐Ÿ” View Creation
๐Ÿ“‹ Order Report View
CREATE VIEW order_report AS SELECT o.id, c.name AS customer_name, p.name AS product_name, o.quantity, o.quantity * p.price AS total_amount, o.date FROM orders o JOIN customers c ON o.customer_id = c.id JOIN products p ON o.product_id = p.id;
How to Use SQL Views:
-- Create a View CREATE VIEW simple_report AS SELECT customer_name, product_name, total_amount FROM order_report WHERE total_amount > 100; -- Use View (like a table) SELECT * FROM simple_report; -- Update View CREATE OR REPLACE VIEW simple_report AS SELECT customer_name, product_name, total_amount, date FROM order_report WHERE total_amount > 150; -- Delete View DROP VIEW simple_report;
Table vs View:
Feature Table View
Data Storage โœ… Physical storage โŒ Virtual (No storage)
Space Usage ๐Ÿ’พ Takes disk space ๐Ÿชถ No space required
Data Freshness โฐ Manual updates ๐Ÿ”„ Always fresh
Complex Queries ๐Ÿ” Rewrite every time โœจ Define once, reuse
Performance โšก Fast (direct access) ๐ŸŒ Slower (query execution)
Practical Examples:
๐ŸŽฏ Simple View (Updatable)
CREATE VIEW mumbai_customers AS SELECT id, name, email FROM customers WHERE city = 'Mumbai'; -- Update data in view UPDATE mumbai_customers SET email = 'newemail@example.com' WHERE id = 101;
๐Ÿ”’ Complex View (Read-only)
CREATE VIEW monthly_sales AS SELECT DATE_FORMAT(date, '%Y-%m') AS month, COUNT(*) AS total_orders, SUM(quantity * price) AS total_revenue FROM orders o JOIN products p ON o.product_id = p.id GROUP BY DATE_FORMAT(date, '%Y-%m'); -- Read-only view (due to GROUP BY) SELECT * FROM monthly_sales;
๐ŸŽฎ Interactive Demo
Click buttons to see how SQL Views work:

๐Ÿ‘† Click the buttons above to explore how SQL Views work!