Home > Database > Mysql Tutorial > How can we create a MySQL view based on another existing view?

How can we create a MySQL view based on another existing view?

王林
Release: 2023-09-10 13:09:02
forward
1357 people have browsed it

我们如何基于另一个现有视图创建 MySQL 视图?

In MySQL, we can create a view based on another existing view. To make it understand we have a view called 'Info' which contains the following data -

mysql> Create view info AS Select Id, Name, Subject FROM student_info;
Query OK, 0 rows affected (0.11 sec)

mysql> Select * from Info;
+------+---------+------------+
| Id | Name | Subject |
+------+---------+------------+
| 101 | YashPal | History |
| 105 | Gaurav | Literature |
| 125 | Raman | Computers |
| NULL | Ram | Computers |
+------+---------+------------+
4 rows in set (0.00 sec)
Copy after login

Now with the following query we are creating a new view called 'info_less' which is based on Existing view 'info' -

mysql> Create view info_less AS Select Id, Name, Subject FROM info WHERE id >= 120;
Query OK, 0 rows affected (0.25 sec)

mysql> Select * from info_less;
+------+-------+-----------+
| Id | Name | Subject |
+------+-------+-----------+
| 125 | Raman | Computers |
+------+-------+-----------+
1 row in set (0.03 sec)
Copy after login

The above is the detailed content of How can we create a MySQL view based on another existing view?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template