SQL Views
Added 29 Jul 2008
A SQL View is a virtual table, which is based on SQL SELECT query.
Essentially a view is very close to a real database table (it has
columns and rows just like a regular table), except for the fact that
the real tables store data, while the views don’t. The view’s data is
generated dynamically when the view is referenced. A view references
one or more existing database tables or other views. In effect every
view is a filter of the table data referenced in it and this filter can
restrict both the columns and the rows of the referenced tables.
Here is an example of how to create a SQL view using already familiar Product and Manufacturer SQL tables:
CREATE VIEW vwAveragePrice AS
SELECT Manufacturer, ManufacturerWebsite, ManufacturerEmail, AVG(Price) AS AvgPrice
FROM Manufacturer JOIN Product
ON Manufacturer.ManufacturerID = Product.ManufacturerID
GROUP BY Manufacturer, ManufacturerWebsite, ManufacturerEmail
Here is an example of how to create a SQL view using already familiar Product and Manufacturer SQL tables:
CREATE VIEW vwAveragePrice AS
SELECT Manufacturer, ManufacturerWebsite, ManufacturerEmail, AVG(Price) AS AvgPrice
FROM Manufacturer JOIN Product
ON Manufacturer.ManufacturerID = Product.ManufacturerID
GROUP BY Manufacturer, ManufacturerWebsite, ManufacturerEmail