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

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

王林
王林forward
2023-09-10 13:09:021280browse

我们如何基于另一个现有视图创建 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)

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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete