CREATE VIEW command creates a virtual table based on a saved query. The resulting view can be accessed via a
SELECT statement, just like a normal table in the database.
CREATE VIEW viewname AS SELECT statements
viewname is a valid SQL name and
SELECT statements can be any valid
SELECT query involving any number of tables and may include
HAVING, or any type of
JOIN. A view can also reference other views as well as tables.
Note: A view will require each column to have a unique name.
The following example creates a view named
student_count_by_country based on a
SELECT statement grouping the
students table by
CREATE VIEW student_count_by_countryASSELECT COUNT(student_name) AS student_count,birth_countryFROM studentsGROUP BY birth_country
Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.
Learn SQL on Codecademy
Analyze Data with SQLLearn to analyze data with SQL and prepare for technical interviews.
Includes 8 Courses