How can we use a combination of logical operators while creating MySQL views?


MySQL views can be created by using a combination of logical operators like AND, OR, and NOT. It can be illustrated with the help of following examples −

Example

mysql> Create or Replace View Info AS select ID, Name, Address , Subject FROM Student_info WHERE (Subject = 'Computers' AND ADDRESS = 'Delhi') OR (Subject = 'History' AND Address = 'Amritsar');
Query OK, 0 rows affected (0.11 sec)

mysql> Select * from Info;
+------+-------+---------+-----------+
| ID   | Name  | Address | Subject   |
+------+-------+---------+-----------+
| 133  | Mohan | Delhi   | Computers |
+------+-------+---------+-----------+
1 row in set (0.00 sec)

Monica Mona
Monica Mona

Student of life, and a lifelong learner

Updated on: 22-Jun-2020

85 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements