0
← Exercises/
Joins•8 of 12
JoinsIntermediatePRO

Feature Matrix Generation with CROSS JOIN

Scenario

Product operations needs a full Cartesian entitlement grid mapping every subscription plan tier to every available feature toggle, marking whether the feature is currently enabled.

Task
1. Generate all pairs of plan tiers from `plans` and features from `features` using a `CROSS JOIN`. 2. Connect to `plan_entitlements` using a `LEFT JOIN` on both `plan_id` and `feature_id`. 3. Compute `is_enabled`: `COALESCE(pe.enabled, false)`. Return: 1. `p.plan_name` 2. `f.feature_key` 3. `COALESCE(pe.enabled, false)` AS `is_enabled` Order results by `p.plan_name` ascending, then by `f.feature_key` ascending.
Expected Output Format

Complete plan-to-feature matrix with enabled status flag.

Input Tables & Sample Data0 tables
Loading database schema...
Need a hint?
query.sql|Local Sandbox
Loading SQL editor...
Click "Run" or press ⌘ + Enter to execute your query

About the “Feature Matrix Generation with CROSS JOIN” SQL Problem

Business Scenario

Product operations needs a full Cartesian entitlement grid mapping every subscription plan tier to every available feature toggle, marking whether the feature is currently enabled.

Expected Output & Criteria

Complete plan-to-feature matrix with enabled status flag.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM

This challenge executes directly against the following relational schema in your browser:

CREATE TABLE plans (
        plan_id INT PRIMARY KEY,
        plan_name VARCHAR(50) NOT NULL
      );

      CREATE TABLE features (
        feature_id INT PRIMARY KEY,
        feature_key VARCHAR(50) NOT NULL
      );

      CREATE TABLE plan_entitlements (
        plan_id INT REFERENCES plans(plan_id),
        feature_id INT REFERENCES features(feature_id),
        enabled BOOLEAN NOT NULL,
        PRIMARY KEY (plan_id, feature_id)
      );

Target SQL Clauses & Operators

CROSS JOINLEFT JOINORDER BY

Want more Joins practice?

Explore the full syllabus of 12 exercises, syntax guides, and interview pitfalls.

View Joins Track→