Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a view in MySQL? [closed]

Tags:

mysql

view

How do I create a view in MySQL?

like image 637
Fero Avatar asked Mar 03 '11 20:03

Fero


People also ask

Can we create views in MySQL?

By default, a new view is created in the default database. To create the view explicitly in a given database, use db_name. view_name syntax to qualify the view name with the database name: CREATE VIEW test.

How do you create a view?

To create a view, a user must have the appropriate system privilege according to the specific implementation. CREATE VIEW view_name AS SELECT column1, column2..... FROM table_name WHERE [condition]; You can include multiple tables in your SELECT statement in a similar way as you use them in a normal SQL SELECT query.

Which of the following syntax is used to create a view in MySQL?

The syntax for the CREATE VIEW statement in MySQL is: CREATE [OR REPLACE] VIEW view_name AS SELECT columns FROM tables [WHERE conditions]; OR REPLACE. Optional.


2 Answers

http://dev.mysql.com/doc/refman/5.5/en/create-view.html

Example:

Create View `MyViewName` as      Select         col1, col2, col3     From         myTable T 
like image 110
mellamokb Avatar answered Sep 22 '22 15:09

mellamokb


CREATE VIEW v AS SELECT * FROM t; 
like image 34
John K. Avatar answered Sep 24 '22 15:09

John K.