A view is a stored query that behaves like a table. It always shows up-to-date data from the underlying tables.
CREATE VIEW name AS SELECT ...;
Query it like a table: SELECT * FROM name;
DROP VIEW name;
Views simplify complex queries and can hide sensitive columns from some users.
💡 Key Takeaways: SQL Views
Mastering SQL Views helps you write clean and reliable SQL code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
SQL Views Code Example
SQL
CREATE VIEW OrderSummary AS
SELECT o.OrderID, c.CustomerName, o.OrderDate,
SUM(p.Price * i.Quantity) AS Total
FROM Orders o
JOIN Customers c ON c.CustomerID = o.CustomerID
JOIN OrderItems i ON i.OrderID = o.OrderID
JOIN Products p ON p.ProductID = i.ProductID
GROUP BY o.OrderID;
SELECT * FROM OrderSummary WHERE Total > 50000 ORDER BY Total DESC;
Free sign-in required · Google login available
SQL Views Practice Exercises
Check what you learned in “SQL Views”.
/ 3 solved
Fill in the blank
Create a view.
PakistaniCustomers AS SELECT * FROM Customers WHERE Country = 'Pakistan';
✓ Correct!Not quite. Try again.
Multiple choice
Does a view store its own copy of the data?
✓ Correct!Not quite. Try again.
Code challenge
Create a view Expensive AS SELECT ProductName, Price FROM Products WHERE Price > 40000, then select everything from it sorted by Price.
Write the code in the live editor. Your answer is checked automatically.