CodeBlanks Logo Icon CodeBlanks

Querying a VIEW

Query a view like a table.

Querying a VIEW

After creating a VIEW you query it with SELECT like a regular table.

SELECT * FROM active_customers;

This query returns active customers.

All columns are selected from active_customers.

Querying a VIEW — details

When queried, the underlying query runs. You can add WHERE and ORDER BY.

For example, SELECT * FROM active_customers WHERE city = 'İzmir' ORDER BY name further filters and sorts the view's result.

Practice Querying a VIEW

Select all columns from the active_customers VIEW.

Starter code

query.sql
-- query view
SELECT *

Sample solution

query.sql
SELECT * FROM active_customers;

Expected output

id  name   status
1   Ayşe   active
2   Mehmet active

Questions and answers

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

1 Querying a VIEW: match the terms

Term Meaning
SELECT * all
FROM source
VIEW virtual
WHERE filter

2 Add FROM

Question
SELECT * ____ active_customers;
Answer
SELECT * FROM active_customers;

Explanation: A view is queried like a table: SELECT * FROM active_customers.

3 Can you add WHERE to a VIEW?

  • Only ORDER BY
  • In some cases
  • No
  • Yes Correct answer

Explanation: You can add WHERE to a VIEW query.

All lessons in Intermediate