• Home
  • Jobs
  • Courses
  • Certifications
  • Companies
  • Online IDE
  • Login
  • Signup
MySQL
  • Introduction To MySQL
  • MySQL RDBMS
  • MySQL SQL
  • MySQL SELECT Statement
  • MySQL WHERE Clause
  • MySQL AND, OR And NOT Operators
  • MySQL ORDER BY Keyword
  • MySQL INSERT INTO Statement
  • MySQL NULL Values
  • MySQL UPDATE Statement
  • MySQL DELETE Statement
  • MySQL LIMIT Clause
  • MySQL MIN() And MAX() Functions
  • MySQL COUNT(), AVG() And SUM() Functions
  • MySQL LIKE Operator
  • MySQL Wildcards
  • MySQL IN Operator
  • MySQL BETWEEN
  • MySQL Aliases
  • MySQL Joins
  • MySQL INNER JOIN Keyword
  • MySQL LEFT JOIN Keyword
  • MySQL RIGHT JOIN Keyword
  • MySQL CROSS JOIN Keyword
  • MySQL Self Join
  • MySQL UNION Operator
  • MySQL GROUP BY Statement
  • MySQL HAVING Clause
  • MySQL EXISTS Operator
  • MySQL ANY And ALL Operators
  • MySQL INSERT INTO SELECT Statement
  • MySQL CASE Statement
  • MySQL NULL Functions
  • MySQL Comments
  • MySQL Operators
  • MySQL CREATE DATABASE Statement
  • MySQL DROP DATABASE Statement
  • MySQL CREATE TABLE Statement
  • MySQL DROP TABLE Statement
  • MySQL ALTER TABLE Statement
  • MySQL Constraints
  • MySQL NOT NULL Constraint
  • MySQL UNIQUE Constraint
  • MySQL PRIMARY KEY Constraint
  • MySQL FOREIGN KEY Constraint
  • MySQL CHECK Constraint
  • MySQL DEFAULT Constraint
  • MySQL CREATE INDEX Statement
  • MySQL AUTO INCREMENT Field
  • MySQL Working With Dates
  • MySQL Views
  • MySQL Data Types
  • MySQL Functions
  • Home
  • Courses
  • MySQL
  • MySQL Views

MySQL Views

Previous Next

MySQL CREATE VIEW Statement

In SQL, a view is a virtual table based on the result-set of an SQL statement.

A view contains rows and columns, just like a real table. The fields in a 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 the data 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;



Practice Excercise Practice now

MySQL CREATE VIEW Examples

The following SQL creates a view that shows all customers from Brazil:
 

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

We can query the view above as follows:
 
SELECT * FROM [Brazil Customers];

The following SQL creates a view that selects every product in the "Products" table with a price higher than the average price:
 
CREATE VIEW [Products Above Average Price] AS
SELECT ProductName, Price
FROM Products
WHERE Price > (SELECT AVG(Price) FROM Products);

We can query the view above as follows:
 
SELECT * FROM [Products Above Average Price];



Practice Excercise Practice now

MySQL Updating A View

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:
 
CREATE OR REPLACE VIEW [Brazil Customers] AS
SELECT CustomerName, ContactName, City
FROM Customers
WHERE Country = 'Brazil';



Practice Excercise Practice now

MySQL Dropping A View

A view is deleted with the DROP VIEW statement.

DROP VIEW Syntax
 

DROP VIEW view_name;

The following SQL drops the "Brazil Customers" view:
 
DROP VIEW [Brazil Customers];



Practice Excercise Practice now

Previous Next
COMPANY
  • About us
  • Careers
  • Contact Us
  • In Press
  • People
  • Companies List
Products
  • Features
  • Coding Assessments
  • Psychometric Assessment
  • Aptitude Assessments
  • Tech/Functional Assessments
  • Video Assessment
  • Fluency Assessment
  • Campus
 
  • Learning
  • Campus Recruitment
  • Lateral Recruitment
  • Enterprise
  • Education
  • K 12
  • Government
OTHERS
  • Blog
  • Terms of Services
  • Privacy Policy
  • Refund Policy
  • Mart Category
Partner
  • Partner Login
  • Partner Signup

Copyright © RVR Innovations LLP 2025 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP