SQLite Views
What is a View?
A view is a stored SELECT statement with a name. You can select from a view as if it was a table, and it always shows the current data.
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Create a View
Example
Create a view with the customers from Brazil:
CREATE VIEW BrazilCustomers AS
SELECT CustomerName, ContactName
FROM Customers
WHERE Country = 'Brazil';
Try it Yourself »
Use the View
Select from the view like a table:
Example
CREATE VIEW IF NOT EXISTS BrazilCustomers AS
SELECT CustomerName, ContactName
FROM Customers
WHERE Country = 'Brazil';
SELECT * FROM BrazilCustomers;
Try it Yourself »
A View With a Calculation
Example
Create and use a view with the products that cost more than the average:
CREATE VIEW IF NOT EXISTS ProductsAboveAverage AS
SELECT ProductName, Price
FROM Products
WHERE Price > (SELECT AVG(Price) FROM Products);
SELECT * FROM ProductsAboveAverage;
Try it Yourself »
Change or Delete a View
SQLite has no CREATE OR REPLACE VIEW. To change a view, delete it and create it again:
Note: In SQLite, views are read only. You cannot insert, update or delete through a view.