
- 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
Display the contents of a VIEW in MySQL?
Following is the syntax −
select * from yourViewName;
Let us first create a table −
mysql> create table DemoTable1388 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(40) -> ); Query OK, 0 rows affected (0.71 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1388(StudentName) values('Chris'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1388(StudentName) values('Bob'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1388(StudentName) values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1388(StudentName) values('Mike'); Query OK, 1 row affected (0.29 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1388;
This will produce the following output −
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | Chris | | 2 | Bob | | 3 | David | | 4 | Mike | +-----------+-------------+ 4 rows in set (0.00 sec)
Following is the query to create view in MySQL −
mysql> create view view1388 as select *from DemoTable1388 where StudentId=3; Query OK, 0 rows affected (0.13 sec)
Now, display the contents of view in MySQL −
mysql> select * from view1388;
This will produce the following output −
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 3 | David | +-----------+-------------+ 1 row in set (0.19 sec)
- Related Articles
- Python - Display the Contents of a Text File in Reverse Order?
- Java Program to display the contents in JTextArea
- PHP: How do I display the contents of a textfile on my page?
- Grant a user permission to only view a MySQL view?
- Show/view indexes in a MySQL Database
- Display Command Output or File Contents in Column Format in Linux
- How to display custom view in ActionBar in Android?
- How to create a MySQL view?
- How do I create a view in MySQL?
- Display a custom alert or a view on receiving a notification in Android
- Display all fields of a table in MySQL?
- How to display Material Chip View in React Native?
- How can we create a MySQL view based on another existing view?
- How to display a list view in an Android Alert Dialog in Kotlin?
- How to create a table from view in MySQL?

Advertisements