Home > Article > Daily Programming > How to create a view in mysql? (Pictures + Videos)
This article mainly introduces how to create a view in mysql.
First of all, everyone must knowWhat is a view?
A view refers to a view in a computer database, which is a virtual table whose content is defined by a query. So this statement may be relatively abstract for novices, but in our previous article, we have given you a detailed introduction to the basic knowledge of mysql data table view. Friends who need to know more can refer to the following article.
[What does mysql data table view mean? What are the uses? 】
The focus of this section is to explain to you how to create a view.
Below we will give you a detailed introduction to how to create a mysql data table view with a simple example.
The syntax for creating a view:
create view + 视图名 + as +select语句
1. Create a single table view
The syntax is as follows:
create view my_v1 as select * from stu;
Here we create a view named my_v1 on the stu data table.
2. Create a multi-table view
The syntax is as follows:
create view my_v2 as select * from stu as left jion class c on s.c_id=c_id;
Here we are Create a view named my_v2 on the two tables stu and class. And this view has four fields, including id (id in stu), name (name in stu), c_id (c_id in stu), title (title in class) fields.
Finally we can check whether the views are created successfully through the Navicat tool.
As shown in the figure, both the single table view and the multi-table view were created successfully.
The data in the my_v2 view is as shown below.
This article is an introduction to the method of creating single table and multi-table views in MySQL. It is also very simple. I hope it will be helpful to friends in need!
If you want to know more about mysql, you can follow the PHP Chinese website mysql video tutorial, everyone is welcome to refer to and learn!
The above is the detailed content of How to create a view in mysql? (Pictures + Videos). For more information, please follow other related articles on the PHP Chinese website!