top of page

Should a Combined Activity Report Use UNION or UNION ALL?

Oct 25
3 min read
UNION vs UNION ALL: Preserve Business Events: Define what one row means; Preserve event identity; Reconcile combined results.

Two teams each submit a row showing that a workshop took place on Tuesday. A combined report displays only one workshop. Nobody deleted an event from either source, yet the final total is wrong. The report may have removed equal-looking rows while combining the datasets.


The right choice between UNION and UNION ALL depends on what the rows mean. Decide whether you need every recorded event or a set of distinct values before choosing the operator. Neither choice can resolve uncertain business identity by itself.


Start with the unit being counted


Write a sentence such as: each output row represents one workshop occurrence. Then identify the fields that distinguish occurrences. A date and workshop title may describe an event without uniquely identifying it. Two separate workshops can share both.


Alternatively, the question might be: which workshop titles appeared in either team's calendar? In that case, distinct titles are the intended result. Removing repeated titles answers the question instead of damaging it. A report specification should make that distinction visible to its reviewer.


Understand what the combination removes


PostgreSQL documents UNION as removing duplicate result rows, while UNION ALL retains them. The inputs must return the same number of columns with compatible corresponding types. The comparison concerns the selected output, not an inferred real-world event identity.


This means changing the selected columns can change what counts as a duplicate. Adding an event identifier may preserve two rows previously collapsed into one. Adding a source label can also make rows different, but that label alone does not prove that two source records describe separate events.


An illustrative workshop fixture


Imagine source A contains event A17, titled Intake Workshop, dated October 21. Source B contains event B09 with the same title and date. The coordinator confirms that these were separate sessions.


Selecting only title and date from both sources with UNION produces one distinct row. UNION ALL produces two rows. For an occurrence report, preserve the event identifiers and source names so a reader can trace each occurrence. For a title catalogue, selecting the distinct title alone may be appropriate.


Now change the story: B09 is a copied record of A17. UNION ALL still returns both records, but the business count should be one occurrence. The correction requires an explicit identity mapping or reviewed consolidation rule. It cannot be inferred safely from matching descriptive fields.


Build a reconciliation before changing the query


Create a small fixture with three situations: genuinely separate events with equal descriptions, one event copied across sources, and an event found in only one source. Write the expected occurrence count and expected catalogue membership independently.


Compare the combined results against those expectations. Inspect identifiers rather than only the total. Two mistakes can cancel numerically: one event disappears while another is counted twice. A matching grand total therefore does not establish that the correct events survived.


Keep the comparison reproducible


Record the input snapshot, selected columns, combination operator, and any identity rule. Have a reviewer explain each output row using the fixture. If that explanation needs information missing from the dataset, treat the business definition as unfinished.


For a live report, make the change in a review environment and preserve the prior output for comparison. A source may legitimately contain repeated observations. Do not automatically remove them merely because the final display looks untidy.


Keep ordering and counting separate


A combined result also needs an explicit ordering rule when presentation order matters. Do not assume one team's rows will always appear before the other's. Ordering changes the reading sequence; it does not repair an incorrect definition of an event.


The handoff should state the question, the row identity, the treatment of copied records, and the reconciliation evidence. This gives the next maintainer a reason for the operator choice and a test that will detect an accidental change.


A useful completion check


Ask a colleague to explain why the equal-looking workshop rows should remain separate or collapse. If the answer is only that one SQL operator is more familiar, the review is incomplete. Release the report when its rows match the intended business objects, including the awkward cases.


Continue with Why Did a Report Total Increase After Adding a Detail Table? for the related planning decision.


The published FutureOS introduction describes the project as being in prelaunch. Use this guide to prepare a concrete project discussion; it does not announce an available FutureOS feature.



Prepared with AI assistance. Primary sources checked on October 25, 2026. Examples and procedures are illustrative editorial guidance, not FutureOS product announcements or an independently reviewed assessment.

Comments


bottom of page