Learn what a Role-Playing Dimension is in plain English—connecting one `dim_user` or `dim_date` table twice (Buyer vs Seller, Order Date vs Ship Date) using clean SQL aliases without attribute collisions.
Think about a single user account `Alice (user_id = 101)` on a marketplace like eBay or TICKIT:
- Last Friday, Alice sold 2 Lakers tickets (seller_id = 101).
- Tonight, Alice bought 2 Taylor Swift tickets (buyer_id = 101).
Should you build two separate identity tables (dim_buyers and dim_sellers) containing two duplicate copies of Alice's name, state, and age?
NO! Imagine Alice moves from Texas to Florida—you'd have to maintain her address in two places!
Instead, you store Alice once inside `dim_users` and let your Fact table point to dim_users twice under two different roles (buyer_id and seller_id). Similarly, `dim_date` serves once for order_date_key and once for event_date_key.
That pattern is called a Role-Playing Dimension.
dim_users, dim_date), then join it multiple times using distinct SQL aliases (buyer, seller) and rename output columns explicitly (buyer_state, seller_state).| Physical Dimension Table | Role 1 Foreign Key | Role 2 Foreign Key | Role 3 Foreign Key |
|---|---|---|---|
| `dim_users` | buyer_id | seller_id | referral_user_id |
| `dim_date` | order_date_key | ship_date_key | event_date_key |
| `dim_airport` | origin_airport_id | destination_airport_id | layover_airport_id |
| `dim_account` | debit_account_id | credit_account_id | fee_account_id |
Suppose `fact_sales` tracks each marketplace settlement between a buyer and a seller:
| sale_id | buyer_id | seller_id | event_date_key | sale_date_key | price_paid |
|---|---|---|---|---|---|
| S1 | 101 | 202 | 20260715 | 20260501 | 240.00 |
| S2 | 202 | 303 | 20260802 | 20260502 | 120.00 |
And `dim_users` stores every user once:
| user_id | full_name | home_state |
|---|---|---|
| 101 | Alice | CA |
| 202 | Bob | NY |
| 303 | Priya | NY |
SELECT
f.sale_id,
buyer.full_name AS buyer_name,
buyer.home_state AS buyer_state,
seller.full_name AS seller_name,
seller.home_state AS seller_state,
d_sale.full_date AS sale_date,
d_evt.full_date AS event_date,
DATEDIFF(d_evt.full_date, d_sale.full_date) AS days_bought_in_advance,
f.price_paid
FROM fact_sales f
JOIN dim_users buyer ON f.buyer_id = buyer.user_id
JOIN dim_users seller ON f.seller_id = seller.user_id
JOIN dim_date d_sale ON f.sale_date_key = d_sale.date_key
JOIN dim_date d_evt ON f.event_date_key = d_evt.date_key
WHERE buyer.home_state <> seller.home_state;Output:
| sale_id | buyer_name | buyer_state | seller_name | seller_state | days_bought_in_advance | price_paid |
|---|---|---|---|---|---|---|
| S1 | Alice | CA | Bob | NY | 75 | 240.00 |
Notice how S2 (Bob NY -> Priya NY) is filtered out cleanly because we compared buyer.home_state <> seller.home_state! And notice `days_bought_in_advance = 75` — role-playing dim_date lets you compare two calendar dates cleanly without messy string parsing!
Wait—what if your BI tool (Power BI / Looker) struggles with two active relationship lines between fact_sales and dim_users?
In Gold, keep 1 physical table (`dim_users`), and create tiny Zero-Copy SQL Views for BI tools:
CREATE OR REPLACE VIEW gold.dim_buyers AS SELECT * FROM gold.dim_users;
CREATE OR REPLACE VIEW gold.dim_sellers AS SELECT * FROM gold.dim_users;Views cost $0 extra storage, stay 100% synced whenever dim_users updates, and make self-service drag-and-drop crystal clear for non-SQL business users!
OR joins doubled every sale row (joining 1 row for the buyer and 1 row for the seller), duplicating revenue 2x! Always use two separate `JOIN` clauses with different aliases.state, state_1) crashes Spark CTAS (CREATE TABLE AS SELECT) immediately! Always prefix output columns (buyer_state, seller_state).dim_users, dim_date) referenced multiple times by different FKs.buyer, seller, d_order, d_ship).buyer_state, seller_state).dim_buyers, dim_sellers) if BI semantic layers disallow multiple active paths.Test your understanding of the concepts covered in this lesson.
In ticketing, multiple dates exist on a single sale: the date the ticket was listed and the date the ticket was sold. Rather than duplicating the date table, dimensional models use "role-playing dimensions" by joining the same date dimension table twice under different aliases.