Skip to content
Learn Netverks

Lesson

Step 27/36 75% through track

views

Views

Last reviewed May 28, 2026 Content v20260528
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches Views: the SQL patterns, schema habits, and query reasoning you need before advancing in SQL.

Teams query Views on every SQL codebase—skipping it leaves gaps in debugging and data reviews.

You will apply Views in contexts like: Postgres, MySQL, SQLite, warehouses, and ORMs that still expose SQL.

Copy SQL from each lesson into SQLite (sqlite3), DB Fiddle, or local Postgres—read result grids and row counts. The in-browser SQL lab (sql_sandbox) will run queries when the runner ships; until then, local clients are the practice path.

When you can explain the previous lesson's ideas without copying example queries verbatim.

A view is a stored SELECT with a name—virtual table for simplifying repeated queries and tightening permissions without duplicating data.

CREATE VIEW

CREATE VIEW customer_spending AS
SELECT c.id,
       c.name,
       COUNT(o.id) AS order_count,
       COALESCE(SUM(o.total), 0) AS spent
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
GROUP BY c.id, c.name;

SELECT * FROM customer_spending ORDER BY spent DESC;

Practice: Advanced features vary by engine—SQLite 3.25+ supports window functions; test your version with a simple query.

Views vs tables

Views do not store rows by default (except materialized views in Postgres and similar). Underlying table changes reflect immediately in view results.

Security and APIs

Grant SELECT on a view exposing safe columns instead of base tables with secrets. ORMs can map views like tables—still prefer migrations for view definitions.

Important interview questions and answers

  1. Q: View vs CTE?
    A: View persists in schema for reuse; CTE is query-local.
  2. Q: Updatable views?
    A: Some simple views allow INSERT/UPDATE—rules vary; often read-only in practice.

Self-check

  1. What SQL statement defines a view?
  2. Do views copy data to disk by default?

Tip: Grant SELECT on views to analytics users instead of exposing sensitive base tables.

Interview prep

View storage?

Stores query definition, not data by default.

View vs CTE?

View persists in schema; CTE is query-scoped.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • View vs table?
  • Materialized view?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump