01 / 20

Communicating Query
Assumptions

Learn how to identify, document, and communicate the hidden assumptions and limitations behind every SQL query you write.

SQL

What Are Query Assumptions?

Every SQL query rests on beliefs about the data that are not checked by the query itself. These beliefs are called query assumptions: things you take for granted about column values, row uniqueness, relationships between tables, and the meaning of NULL.

Why Communication Matters

SQL queries are often shared with teammates, managers, and stakeholders who rely on the results to make decisions. If your assumptions are wrong or unstated, the conclusions drawn from the data will be misleading.

✓ Transparency
Others can verify your logic and spot flawed assumptions before decisions are made.
✓ Reproducibility
Documented assumptions let anyone re-run your query in the future and know what to expect.
✓ Trust
Stating limitations up front builds credibility, even when results are imperfect.

The Hidden Iceberg of a Query

waterline SELECT ... FROM ... WHERE ... GROUP BY Visible Query No duplicate rows NULLs are irrelevant Data is up to date
JOIN keys match \(1:1\)
Column types are correct Hidden Assumptions

The Core Rule

This means that communicating assumptions is not optional: it is part of writing correct, professional SQL. A query without documented assumptions is like a math proof without stating its premises.

Five Categories of Assumptions

Query Assumptions 1. Data Completeness 2. Data Quality 3. Relationships 4. Temporal Scope 5. Business Logic

Assumptions vs. Limitations

Assumption Limitation
Definition A belief about the data you treat as true A known constraint on what your query can show
Who controls it The data source (you hope it holds) You, the query writer
Example email column has no duplicates Query only covers the last 90 days
If wrong Results are silently incorrect Results are correct but incomplete

How to Identify Assumptions

1
Read each clause. For every WHERE, JOIN, and GROUP BY, ask: "What must be true in the data for this to work?"
2
Check for NULLs. Does your query handle missing values, or silently exclude them?
3
Examine JOINs. Are you assuming a one-to-one relationship? Could duplicates inflate counts?
4
Question time ranges. Does the data cover the period you intend? Is there a lag in loading?
5
Validate business terms. Does "active customer" mean the same thing to everyone?

How to Communicate Them

1
Inline comments. Place SQL comments (--) next to the clause they explain.
2
Header block. Begin every query file with a comment block listing key assumptions and known limitations.
3
Companion document. For dashboards and reports, attach a short "Data Notes" section describing scope and caveats.
4
Verbal walkthrough. When presenting results, state assumptions out loud before showing numbers.

Example 1: Active Users

-- Assumptions: -- 1. "active" means status = 'active' (no other spellings) -- 2. Each user has exactly one row in users -- Limitation: Only counts users who logged in this year SELECT COUNT(user_id) AS active_count FROM users WHERE status = 'active' AND last_login >= '2024-01-01';

Example 2: Revenue by Region

-- Assumptions: -- 1. orders.customer_id always matches customers.id (no orphans) -- 2. Each order belongs to exactly one customer -- 3. region is never NULL in customers -- Limitation: Does not filter out refunded orders (e.g., where \( \text{amount} < 0 \)). SELECT c.region, SUM(o.amount) AS total_revenue FROM orders o JOIN customers c ON o.customer_id = c.id GROUP BY c.region;

Example 3: Churn Rate

-- Assumptions: -- 1. A "churned" customer has no order in the last 90 days -- 2. The orders table is current as of today -- 3. cancelled_at being NULL means the account is still open -- Limitations: -- - Does not account for seasonal buying patterns -- - Free-trial users are included in the denominator SELECT ROUND( COUNT(CASE WHEN last_order < CURRENT_DATE - 90 THEN 1 END) * 100.0 / COUNT(*), 1 ) AS churn_pct FROM customer_summary WHERE cancelled_at IS NULL;

The Communication Flow

Write Query List Assumptions State Limitations Document in Code Share with Stakeholders Validate and Iterate

Common Mistakes

✕ Assuming No NULLs
Forgetting that NULL values are silently excluded by WHERE clauses and aggregate functions like COUNT(column).
✕ Ignoring JOIN Type
Using INNER JOIN without stating that unmatched rows are dropped: this silently changes your row count.
✕ Undefined Terms
Using phrases like "active user" without defining what "active" means in the context of your query.

Summary Reference

Category Ask Yourself How to Communicate
Completeness Is all relevant data present? "Excludes rows where X is NULL"
Quality Are values consistent and accurate? "Assumes status is always lowercase"
Relationships Are JOINs \(1:1\) or \(1:\text{many}\)? "JOIN may duplicate rows if \(1:\text{many}\)"
Temporal Does the time range cover the need? "Data covers Jan 1 to today only"
Business Logic Do terms mean the same to everyone? "'Churned' means no order in 90 days"

Question 1 of 5

A colleague writes a query using INNER JOIN between orders and customers. They report total revenue. What is the most important assumption to communicate?

Question 2 of 5

What is the difference between a query assumption and a query limitation?

Question 3 of 5

Which assumption is most critical to communicate about this query?

Question 4 of 5

Your query uses COUNT(email) to count customers. A teammate points out that some customers have NULL email addresses. What is the best response?

Question 5 of 5

Which of the following is the best practice for documenting query assumptions in a shared codebase?