Select*fromStudent_info;+------+---------+--------- ---+----------------+|id |Name |Address |Sub"> How can we create a MySQL view by selecting some range of values ​​from a base table?-Mysql Tutorial-php.cn

How can we create a MySQL view by selecting some range of values from a base table?

PHPz
Release: 2023-08-27 21:45:03
forward
698 people have browsed it

我们如何通过从基表中选择某些范围的值来创建 MySQL 视图?

We know that MySQL BETWEEN operator can be used to select a value from a range of values. We can use the BETWEEN operator with views to select a certain range of values from the base table. To understand this concept, we use the base table "student_info" with the following data -

mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | | 133 | Mohan | Delhi | Computers | +------+---------+------------+------------+ 6 rows in set (0.00 sec)
Copy after login

Example

The following query will create a view named "Info" by using the "BETWEEN" operation operator to select certain values within a specific range -

mysql> Create or Replace view Info AS SELECT * from student_info WHERE Name BETWEEN 'C' AND 'P'; Query OK, 0 rows affected (0.14 sec) mysql> Select * from info; +------+--------+------------+------------+ | id | Name | Address | Subject | +------+--------+------------+------------+ | 105 | Gaurav | Chandigarh | Literature | | 133 | Mohan | Delhi | Computers | +------+--------+------------+------------+ 2 rows in set (0.00 sec)
Copy after login

Similarly, we can use NOT with the BETWEEN operator to select a range that is different from the values written in the query-

mysql> Create or Replace view Info AS SELECT * from student_info WHERE Name NOT BETWEEN 'C' AND 'P'; Query OK, 0 rows affected (0.06 sec) mysql> Select * from Info; +------+---------+------------+-----------+ | id | Name | Address | Subject | +------+---------+------------+-----------+ | 101 | YashPal | Amritsar | History | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | +------+---------+------------+-----------+ 4 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How can we create a MySQL view by selecting some range of values from a base table?. 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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!