Quick revision
The short answer
Wrong joins come from implicit grain: analysts do not know what one row of each table represents or which join paths are safe. I would encode correct grain and join paths in a tested, versioned data model in a warehouse, as a star schema with fact tables at one grain and dimensions joined by key, exposed through a semantic layer or curated views, and run analytics on a replica or warehouse instead of production. Training supports this but cannot replace it, and I would measure conflicting metric definitions and report correctness incidents.
What to remember
In this answer, we traced wrong joins to implicit grain and multiple join paths in a normalised schema. Training raises awareness but does not scale, and views on OLTP tables encode joins but still load production. A tested, versioned star schema in a warehouse makes grain explicit, a semantic layer defines metrics once, and training then teaches a simpler model. We measured success by conflicting metric definitions, correctness incidents and production load.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Wrong joins come from implicit grain: analysts do not know what one row of each table represents or which join paths are safe. I would encode correct grain and join paths in a tested, versioned data model in a warehouse, as a star schema with fact tables at one grain and dimensions joined by key, exposed through a semantic layer or curated views, and run analytics on a replica or warehouse instead of production. Training supports this but cannot replace it, and I would measure conflicting metric definitions and report correctness incidents.
Why this question is asked
When many people query a normalised schema with a dozen core tables, everyone eventually writes a join that multiplies rows or joins on the wrong path, and numbers drift apart across reports. The choice between views, a semantic layer, denormalised reporting tables and training is a real design decision with cost, ownership and load implications. Interviewers ask it at senior levels to see whether we diagnose the cause before picking a tool. In this answer, we will name the real cause, weigh each option with what it costs, explain the combination I would choose and why, and say how we would know it worked.
1The Real Cause: Implicit Grain
Grain is what one row of a table or result represents: one order, one order line, one payment, one customer per day. Fan-out errors happen when a query joins tables of different grain and then aggregates, such as summing order totals after joining to order lines. Wrong-path errors happen when there are several ways to connect two tables, for example orders to region through the billing address or through the shipping address, and different analysts pick different paths.
In an OLTP schema, the operational database the application writes to, grain and correct join paths are knowledge in people's heads. With 12 core tables, there are dozens of possible join paths, and every analyst must rediscover the safe ones. So the fix must make grain and paths explicit somewhere that queries can rely on, rather than asking each person to remember them.
2Weighing the Options
Each option addresses part of the problem, at a different cost.
| Option | What it fixes | Cost and limits |
|---|---|---|
| Training | awareness of grain and fan-out | does not scale; turnover; still error-prone |
| Views on OLTP tables | encodes join paths once | still loads production; slow wide views |
| Star schema in a warehouse | grain explicit: facts + dimensions | pipeline to build and own; some latency |
| Semantic layer on the model | metrics defined once, joins generated | tooling and governance effort |
| Tested, versioned models | changes reviewed, outputs checked | engineering discipline in the data team |
Training alone is the cheapest to start and the weakest on its own. Even well-trained analysts make fan-out mistakes under deadline, new people arrive every month, and nothing stops two people encoding revenue differently.
Curated views over the OLTP tables are a real improvement: a view like order_facts can encode the correct joins once. But views are just stored queries, so every analyst query still runs against the production database, competing with customer traffic, and wide views over many joins can be slow. They also do not stop someone joining a view to another table at the wrong grain.
3Making Grain Explicit With a Star Schema
A star schema is a reporting model with fact tables in the middle and dimension tables around them. A fact table records events at one declared grain, for example fact_order_line with one row per order line, holding numeric measures such as quantity and net amount, plus keys to dimensions. Dimension tables describe the things events refer to, such as dim_customer, dim_product and dim_date, each with one row per entity.
The design makes grain impossible to miss: the table name and its documentation say what a row is, measures live only on facts at their own grain, and dimensions join to facts by a single key, so there is one join path. Sums over a fact table are safe because no join from a fact to a dimension can multiply fact rows. Revenue per region per month becomes a join of fact_order_line to dim_customer and dim_date, and there is only one way to write it.
4A Semantic Layer on Top
A semantic layer is a definition of business metrics and dimensions, such as revenue, active customers or region, written once against the model, from which tools generate SQL. Analysts pick revenue by region by month and get a query with the correct joins and the agreed definition, net of refunds or not, as decided. Several BI tools and data modelling tools offer this. It is the strongest protection against conflicting definitions, because the definition is not rewritten in each report.
5What I Would Choose and Why
I would not pick one option but a combination with a clear order. First, move analytics off the production database to a warehouse, or at least a replica, because heavy analytical joins should never compete with customers. Second, build a small star schema for the most used subject areas, orders, payments, customers, as tested and versioned models, with tools in the style of dbt, where each model is SQL in version control, changes go through review, and tests assert things like unique keys and non-null foreign keys, plus checks that totals match the source system. Third, put a semantic layer or certified views on top for the core metrics. Fourth, train analysts on the model, which is much easier to teach than 12 raw tables, and on grain as a concept.
This costs a data engineering team and a pipeline with some latency, often hourly or daily, which is acceptable for most reporting. Raw table access can remain for exploratory work, clearly labelled as uncertified.
- BI tools and analyst queriespick metrics, not join paths
- Semantic layer / certified viewsrevenue, active customers defined once
- Star schema modelsfacts at one grain, dimensions by key; tested, versioned
- Warehouse or replicaloaded from OLTP; analytics load kept off production
- OLTP database12 core tables, serves the application
5 layers, from the top down. Step through them one at a time.
6How We Know It Worked
We measure two things before and after. One is the number of conflicting definitions of key metrics, found by inventorying how reports compute revenue, orders and active customers. The other is report correctness incidents: corrections issued after a number was published, and tickets from finance about mismatches. A good result is most frequently used reports running on certified models within two quarters, with correctness incidents clearly falling. We also watch the load on the production database from analytical queries, which should drop to near zero.
7Follow-up questions
Is a semantic layer worth it for a small company?
With five analysts and a few reports, a handful of well-documented views on a replica may be enough. The semantic layer pays off when many people and tools produce numbers that must agree, because then the cost of conflicting definitions grows faster than the cost of the tooling.
What about denormalised wide tables instead of a star schema?
A single wide table at one grain, such as one row per order line with customer and product attributes copied in, is easy to query and works well for a narrow use case. It becomes hard to maintain when many subject areas are needed, and attributes duplicated per row make changes such as a customer moving region tricky. Star schemas keep that flexibility with modest extra complexity.
Who should own the models?
A data or analytics engineering team owns the models and their tests, while business owners, such as finance for revenue, own the metric definitions. Without named owners, models drift back into a collection of individually written queries.
8Conclusion
In this answer, we traced wrong joins to implicit grain and multiple join paths in a normalised schema. Training raises awareness but does not scale, and views on OLTP tables encode joins but still load production. A tested, versioned star schema in a warehouse makes grain explicit, a semantic layer defines metrics once, and training then teaches a simpler model. We measured success by conflicting metric definitions, correctness incidents and production load.
Open with
I would start from the cause. Analysts get fan-out and wrong joins because the grain of each table and the correct join paths are implicit: with 12 normalised tables there are many ways to join, and each person has to rediscover the safe ones.
Then, if they want more
Training helps, but on its own it does not scale and does not stop two people defining revenue differently. Views over the OLTP tables encode the joins once, which is better, but every query still hits production, and nothing stops joining a view at the wrong grain. So my choice is a combination.
First, analytics move to a warehouse or at least a replica. Second, we build a star schema for the main subject areas, fact tables with one declared grain, like one row per order line, and dimensions joined by a single key, so sums are safe and there is one join path.
Those models are versioned SQL with tests in a dbt-like workflow, reviewed like code, with checks that totals reconcile to the source. Third, a semantic layer or certified views define core metrics like revenue once, so tools generate the joins. Then training becomes much easier because people learn a clean model and the concept of grain.
I would measure conflicting metric definitions and report correction incidents before and after, and expect both to drop within a couple of quarters.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, The SQL Language
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Analysts across the company write reports joining 12 core tables and frequently get...": https://scrivio-interview-library.netlify.app/databases/sql-joins-and-subqueries/f320661de5/