SQL Views

A saved query that behaves like a table — but always reflects the live, current data underneath it.

What & Why

A view is a named, stored query. Selecting from a view runs that underlying query fresh every time — a view never stores its own copy of data, it's just a saved shortcut for a SELECT you'd otherwise have to retype.

See How It Works

BUSINESS QUESTION

Define a reusable active-campaign result from the real marketing table.

idnamechannelspendstart_dateend_datestatustarget_segment
1Spring Launchgoogle_ads55000.002024-01-152024-03-31activesmb
2Retention Webinaremail45000.002024-02-102024-04-15activeenterprise
3Finance Retargetinglinkedin50000.002024-03-122024-05-31activeenterprise
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30activeenterprise
EXAMPLE QUERY
CREATE VIEW public.active_campaign_summary AS
SELECT
  id AS campaign_id,
  name,
  channel,
  spend,
  start_date,
  end_date
FROM marketing.campaigns
WHERE status = 'active';
RESULT — public.active_campaign_summary
campaign_idnamechannelspendstart_dateend_date
1Spring Launchgoogle_ads55000.002024-01-152024-03-31
2Retention Webinaremail45000.002024-02-102024-04-15
3Finance Retargetinglinkedin50000.002024-03-122024-05-31
4Enterprise Searchgoogle_ads60000.002024-04-012024-06-30

The standard view exposes the six-column active-campaign contract while reading current marketing.campaigns rows.

This lesson's practice is part of Pro.

Advanced business practice

Sign up free to try it on a real business scenario