Simple Example to Create View in MySQL

MySql View is very important factor of Database based on performance. View is virtual table that’s contains result set of your SQL statement. In SQL statement yo can use SQL functions, WHERE, and JOIN statements to get result set.
The View table can contain rows and column like your original table the column name may be different and unique in VIEW table. By default, the names of the columns retrieved by the SELECT statement are used for the view column names. The Columns name in view may be one or more real tables in the database.

Create view in mysql Syntax

Select Code
1
2
3
4
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition

A view can belong to a database. By default, a new view is created in the default database. To create the view explicitly in a given database, specify the name as db_name.view_name:

Create view in mysql with Example

Select Code
1
2
3
4
CREATE VIEW test.view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition

Where: test is the database name