O'Reilly logo

Sams Teach Yourself MySQL by Chris Newman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Understanding Views

A view is a pseudo-table. In SQL, you can reference a view just like you reference a table in a SELECT statement. You can also use some views with INSERT, UPDATE, and DELETE statements.

Views are a tool of convenience. For example, if you find yourself frequently performing the same join, you might find it more convenient to create a view to use in your queries instead.

Creating a View

You create a view with the CREATE VIEW command. The following example creates a simple view—every column from the customer_contacts table is included, but a WHERE clause restricts the rows returned to only those with the given customer_code.

mysql> CREATE VIEW custview AS
    -> SELECT * FROM customer_contacts
    -> WHERE customer_code = 'SCICORP'; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required