SQL Practice Logo

SQLPractice Online

Views & Materialized Views: Functions

Module: Schema Design & Advanced DDL

CREATE VIEW view_name AS SELECT columns FROM tables;

CREATE MATERIALIZED VIEW mv_name AS SELECT columns FROM tables;

REFRESH MATERIALIZED VIEW mv_name;

REFRESH MATERIALIZED VIEW CONCURRENTLY mv_name;

DROP VIEW view_name;

DROP MATERIALIZED VIEW mv_name;

CREATE VIEW name AS SELECT - creates virtual table, no data stored

CREATE MATERIALIZED VIEW name AS SELECT - stores query results on disk

REFRESH MATERIALIZED VIEW name - update stored results

REFRESH MATERIALIZED VIEW CONCURRENTLY name - refresh without blocking queries

DROP VIEW / DROP MATERIALIZED VIEW - remove view

CREATE INDEX ON materialized_view - index for fast queries

Full support for both views and materialized views, CONCURRENTLY refresh

Views supported, no native materialized views (use tables + triggers)

Views and indexed views (similar to materialized views)

Views and materialized views with automatic refresh options

Core references in this topic include WHERE, =, <, >, <=, >=. Learn what each one does, when to use it, and the execution or engine rules that matter.

WHERE

Filters rows before projection and sorting. It decides which rows continue through the query pipeline.

SELECT ... FROM table WHERE condition;

Most performance issues start with a weak WHERE clause or a missing supporting index.

=

Returns rows where the left and right values are exactly equal.

column = value

Use with exact matches. Do not use = NULL.

<, >, <=, >=

Range comparison operators for less-than, greater-than, and inclusive boundary checks.

salary >= 80000

BETWEEN

Checks whether a value falls inside an inclusive lower/upper range.

order_total BETWEEN 100 AND 500

LIKE

Pattern-matching operator for wildcard string searches.

name LIKE 'Joh%'

DATE

Stores a calendar date without any time-of-day component.

DATE '2026-04-18'

PRIMARY KEY

Uniquely identifies each row and implicitly requires NOT NULL.

customer_id INT PRIMARY KEY