🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to MySQL Notes
Topic #62

MySQL Views


MySQL CREATE VIEW Statement

An SQL view is a virtual table based on the result-set of an SQL statement. An SQL view contains rows and columns, just like a real table. The fields in the view are fields from one or more real tables in the database.

You can add SQL statements and functions to a view and present the data as if it were coming from one single table.

A view is created with the CREATE VIEW statement.

CREATE VIEW Syntax

CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

Note: A view always shows real-time data! The database engine only stores the view's definition (the SELECT statement), not a copy of the data.


CREATE VIEW Examples

The following SQL creates a view named "brazil_customers_view", that shows all customers from Brazil:

Example

CREATE VIEW brazil_customers_view AS
SELECT CustomerName, ContactName
FROM Customers
WHERE Country = 'Brazil';

To query the view above, use the following SQL syntax:

Example

SELECT * FROM brazil_customers_view;

The following SQL creates a view named "products_above_average_price", that selects all products in the "Products" table with a Price higher than the average price:

Example

CREATE VIEW products_above_average_price AS
SELECT ProductName, Price
FROM Products
WHERE Price > (SELECT AVG(Price) FROM Products);

To query the view above, use the following SQL syntax:

Example

SELECT * FROM products_above_average_price;

CREATE OR REPLACE VIEW Statement

In MySQL, a view can be updated with the CREATE OR REPLACE VIEW statement.

CREATE OR REPLACE VIEW Syntax

CREATE OR REPLACE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

The following SQL adds the "City" column to the "brazil_customers_view" view:

Example

CREATE OR REPLACE VIEW brazil_customers_view AS
SELECT CustomerName, ContactName, City
FROM Customers
WHERE Country = 'Brazil';

DROP VIEW Statement

A view is deleted with the DROP VIEW statement.

DROP VIEW Syntax

DROP VIEW view_name;

The following SQL drops the "brazil_customers_view" view:

Example

DROP VIEW brazil_customers_view;

Want to go beyond the notes?

Join CodingNow 2.0's MySQL course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

MySQL Views – FAQs

Quick answers about learning MySQL Views in MySQL.

This free note from CodingNow 2.0 explains MySQL Views in MySQL — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every MySQL topic on CodingNow 2.0, including MySQL Views, is 100% free with no signup required.
With focused practice, most students grasp MySQL Views in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now