CodeBlanks Logo Icon CodeBlanks

CREATE VIEW

Save a query as a view.

CREATE VIEW

With CREATE VIEW you name a query. It can later be used like a table.

CREATE VIEW expensive_products AS
SELECT name, price FROM products WHERE price > 100;

VIEW for expensive products.

The view expensive_products is created. name, price is selected from products. WHERE keeps only the rows where price > 100 holds.

CREATE VIEW — details

The VIEW name is used like a table name. You write SELECT * FROM expensive_products.

As long as the view definition stays the same, reports using it don't change; you only update the underlying query in one place.

Practice CREATE VIEW

Create the expensive_products VIEW for products over 100.

Starter code

query.sql
-- expensive products view
CREATE VIEW expensive_products

Sample solution

query.sql
CREATE VIEW expensive_products AS
SELECT name, price FROM products WHERE price > 100;

Expected output

VIEW oluşturuldu

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Add AS

Question
CREATE VIEW expensive_products ____
SELECT name, price FROM products WHERE price > 100;
Answer
CREATE VIEW expensive_products AS
SELECT name, price FROM products WHERE price > 100;

Explanation: After the view name come AS and the view's query.

2 How is a VIEW queried?

  • INSERT ile
  • ALTER ile
  • SELECT ile Correct answer
  • DROP ile

Explanation: A VIEW is queried with SELECT.

3 CREATE VIEW: match the terms

Term Meaning
CREATE VIEW create
AS name
SELECT query
FROM source

All lessons in Intermediate