
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to use MySQL VIEW with WHERE clause?
For MySQL VIEW with WHERE clause, the syntax is as follows −
select * from yourViewName where yourColumnName='yourValue';
Let us first create a −
mysql> create table DemoTable1432 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentBranchName varchar(20) -> ); Query OK, 0 rows affected (1.26 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1432(StudentName,StudentBranchName) values('Chris','CS'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1432(StudentName,StudentBranchName) values('David','CE'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1432(StudentName,StudentBranchName) values('Mike','ME'); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select −
mysql> select * from DemoTable1432;
This will produce the following output −
+-----------+-------------+-------------------+ | StudentId | StudentName | StudentBranchName | +-----------+-------------+-------------------+ | 1 | Chris | CS | | 2 | David | CE | | 3 | Mike | ME | +-----------+-------------+-------------------+ 3 rows in set (0.00 sec)
Following is the query to create view −
mysql> create view DemoTable1432_View as select * from DemoTable1432; Query OK, 0 rows affected (0.17 sec)
Following is the query to use MySQL view with where clause −
mysql> select * from DemoTable1432_View where StudentBranchName='CS';
This will produce the following output −
+-----------+-------------+-------------------+ | StudentId | StudentName | StudentBranchName | +-----------+-------------+-------------------+ | 1 | Chris | CS | +-----------+-------------+-------------------+ 1 row in set (0.03 sec)
- Related Articles
- How to use MySQL Date functions with WHERE clause?
- How Can we use MySQL DISTINCT clause with WHERE and LIMIT clause?
- How can we use two columns with MySQL WHERE clause?
- How can we use ASCII() function with MySQL WHERE clause?
- How can we use CHAR_LENGTH() function with MySQL WHERE clause?
- How can we use BIN() function with MySQL WHERE clause?
- How can we use FIND_IN_SET() function with MySQL WHERE clause?
- How can we use MySQL INSTR() function with WHERE clause?
- How can I use SPACE() function with MySQL WHERE clause?
- How can we use WHERE clause with MySQL INSERT INTO command?
- How can we use MySQL REVERSE() function on column’s data along with WHERE clause?
- How can we create a MySQL view with GROUP BY clause?
- How can we create the MySQL view with ORDER BY clause?
- Can we use WHERE clause inside MySQL CASE statement?
- How can MySQL REPLACE() function be used with WHERE clause?

Advertisements