
- 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 can we create MySQL views with column list?
As we know that while creating a view, providing the list of columns is optional. But if we are providing the name of the columns while creating the view then the number of names in the list of columns must be the same as the number of columns retrieved by the SELECT statement.
Example
The following example will illustrate by creating the views with column list −
mysql> Select * from student_detail; +-----------+-------------+------------+ | Studentid | StudentName | address | +-----------+-------------+------------+ | 100 | Gaurav | Delhi | | 101 | Raman | Shimla | | 103 | Rahul | Jaipur | | 104 | Ram | Chandigarh | | 105 | Mohan | Chandigarh | +-----------+-------------+------------+ 5 rows in set (0.17 sec) mysql> Create view View_student_detail_columns AS SELECT Studentid, StudentName FROM Student_Detail; Query OK, 0 rows affected (0.10 sec)
In the above, we have given two columns and after running the query to get data from view it will show only the column names we have given while creating it.
mysql> Select * from View_Student_detail_columns; +-----------+-------------+ | Studentid | StudentName | +-----------+-------------+ | 100 | Gaurav | | 101 | Raman | | 103 | Rahul | | 104 | Ram | | 105 | Mohan | +-----------+-------------+ 5 rows in set (0.08 sec)
- Related Articles
- How can we create MySQL views without any column list?
- How can we create MySQL views?
- How can we see the list of views stored in a particular MySQL database?
- How can we use logical operators while creating MySQL views?
- Where MySQL views can be inconsistent and how can we ensure their consistency?
- How can we create a MySQL view with LEFT JOIN?
- How can we create a MySQL view with INNER JOIN?
- How can we create a MySQL view with RIGHT JOIN?
- How can we create a MySQL view with a subquery?
- How can we combine ROW selection with COLUMN selection in MySQL?
- How can we use a combination of logical operators while creating MySQL views?
- Can we use backticks with column value in MySQL?
- How to get a list of MySQL views?
- How can we fetch a MySQL SET column as a list of integer offset?
- How can we create a MySQL view with GROUP BY clause?

Advertisements