Why Duplicate Rows Are Sometimes the Truth We Need
Hatched by Deepali K.
May 11, 2026
9 min read
6 views
91%
The hidden question behind every merge
What if the real choice in data work is not between right and wrong, but between preserving reality and cleaning it up?
That sounds abstract until you hit a practical problem. You have two tables, two reports, or two lists of events, and you want to combine them. One option quietly removes repetition. Another keeps every repeated row exactly as it is. At first glance, duplicates look like noise, something to eliminate as soon as possible. But in many systems, repetition is not an accident. It is a signal, a record of frequency, overlap, or conflict. The deeper question is this: when we combine information, are we trying to build a tidier story, or are we trying to preserve the shape of the world?
This tension sits at the heart of set operations in SQL. When separate SELECT statements are joined into a compound select statement, the rules become strict: the queries must line up column for column, and datatype for datatype. You cannot simply throw together anything that looks related. The structure must match. But once the structure matches, there is still a philosophical choice to make: do we collapse repeats, or do we keep them?
That choice matters more than it first appears.
Structure is not bureaucracy, it is meaning
The requirement that each SELECT statement has the same number of columns and aligned datatypes can feel like a technical annoyance. In fact, it is a powerful constraint that reveals something important: combination only works when categories are comparable.
Imagine trying to stitch together two photo albums. If one album labels each image by date and location, while the other labels by mood and subject, you can still combine them, but only if you first decide what role each slot plays. The first column in one query has to mean the same kind of thing as the first column in the other. Otherwise, the output is not a unified dataset, it is a confused collage.
This is why set operators are more than syntax. They encode a discipline of thought. Before you merge sources, you must answer: what is the common axis of comparison? Are you matching person to person, order to order, event to event, or something else entirely? The database will not let you be vague. That is a feature, not a limitation.
A merge is only as honest as the categories it preserves.
This applies far beyond SQL. In business, analytics, research, and even writing, problems often arise when we combine unlike things too quickly. We want one dashboard, one narrative, one spreadsheet, one answer. But structure is what prevents false equivalence. If the columns do not align, the result is not integration. It is distortion.
The rigidity of compound select statements teaches a subtle lesson: good synthesis begins with disciplined alignment. The world may be messy, but our representations cannot afford to be sloppy.
The moral prejudice against repetition
Most people meet duplicate rows with suspicion. Repetition looks inefficient, maybe even embarrassing. If two records are the same, why keep both? Surely one is enough.
That instinct is understandable, but it hides an assumption: that duplicates are always redundancy rather than evidence. In many contexts, a repeated row means something happened twice, was observed twice, or belongs to two overlapping sets. Removing duplicates can be useful, but it is not neutral. It changes the story.
This is where UNION and UNION ALL embody two different philosophies of combination. One suppresses repeated rows. The other keeps them. In effect, one says, “I care about distinct values.” The other says, “I care about all occurrences.” Neither is universally better. They answer different questions.
Consider a simple example. Suppose one table lists customers who signed up on a website, and another lists customers who attended a webinar. If the same person appears in both, a deduplicating merge tells you who the unique individuals are. That is useful if you are counting people. But if you want to know how many times someone engaged across channels, collapsing the duplicate hides the very behavior you care about.
Now think about inventory, fraud detection, log analysis, or survey responses. Repetition might mean heavy usage, repeated transactions, multiple exposures, or conflicting evidence. To blindly remove duplicate rows is to assume the world is a set when it may actually be a multiset, a world where frequency matters.
This is the real insight: duplication is not merely a problem of cleanliness, it is a question of interpretation.
UNION and UNION ALL as two ways of telling the truth
There is a temptation to treat one operator as the default and the other as the exception. That is a mistake. These operators reflect two distinct truths about data.
UNION tells the truth of distinct identity. It is the right tool when you want to know what unique items exist across multiple sources. If two systems report the same person, product, or category, UNION asks the carefully narrowed question: what remains after we abstract away the repeats?
UNION ALL tells the truth of occurrence. It preserves every row, every repetition, every overlap. It does not pretend that repeated facts are the same as unique facts. If the same record appears three times, that may be exactly what you need to know.
The difference is easier to understand with a physical analogy. Imagine two stacks of paper invoices. UNION is like making a list of unique invoice numbers across both stacks. UNION ALL is like combining the stacks and counting every sheet. If you are auditing, the second may be essential. If you are checking coverage, the first may be enough.
The deeper lesson is that a data operation is also a declaration of intent. Choosing UNION says, “I am modeling the set of unique things.” Choosing UNION ALL says, “I am modeling the full stream of events.” Many mistakes in analysis happen because people choose a merge operator before deciding which world they are trying to describe.
The real question is not whether rows repeat. The real question is whether repetition is meaning.
That framing changes everything. Once you see it, duplicate rows stop looking like imperfections and start looking like either evidence or clutter, depending on the question.
Why order comes last, and why that matters mentally
There is another constraint in compound selects that is easy to overlook: ORDER BY and LIMIT can only occur after the last SELECT clause. First the sets are combined, then the final result is sorted or trimmed.
This is more than a rule for query syntax. It reflects a useful mental model for reasoning.
You cannot meaningfully rank what has not yet been assembled. You cannot know the top of a list until the list exists. If you sort too early, you are only ordering fragments. If you limit too soon, you may exclude rows that would matter after the full combination. The sequence matters because composition precedes judgment.
Think of it like assembling a jury. You do not rank individual candidates from separate pools and then pretend the final pool is already known. First you establish the complete eligible set, then you apply your ordering criteria. The database insists on that order because it guards against premature conclusions.
This principle shows up everywhere. In hiring, you combine applicants before scoring them. In product analysis, you gather all relevant events before deciding what is most important. In writing, you collect evidence before arranging the argument. When we skip this order in our thinking, we often confuse local patterns for global ones.
The restriction on ORDER BY and LIMIT is therefore a quiet warning: do not optimize the fragments and mistake that for understanding the whole.
A practical framework: decide what kind of world you are modeling
If these operators teach anything, it is that combining data requires a prior decision about reality. Before writing a query, ask which of these four worlds you are in.
1. The world of unique entities
Use a deduplicating approach when each row should represent a distinct thing. Examples include unique users, products, institutions, or categories. Here, repetition is noise because the unit of meaning is identity.
2. The world of repeated events
Use a preserving approach when each row represents an occurrence, not a type. Examples include page views, transactions, clicks, logs, or signups. Here, repetition is not noise. It is the countable substance of the system.
3. The world of overlapping evidence
Sometimes two sources report the same fact. The fact may be real in both places, or the overlap may reveal data quality issues. In these cases, choosing whether to keep duplicates is a decision about whether you care more about consensus or provenance.
4. The world of staged analysis
If you still need to sort, rank, filter, or limit, do not do it too early. First assemble the full result. Then inspect it. Then decide what deserves priority.
This framework helps because it shifts the question away from “Which operator is right?” and toward “What is the shape of the phenomenon I am modeling?” That is the more mature question. It prevents a common failure mode, where analysts use a deduplicating merge because it looks cleaner, only to erase critical frequency information.
Key Takeaways
-
Do not treat duplicate rows as automatically bad. Ask whether repetition represents noise, frequency, overlap, or evidence.
-
Use structural alignment as a check on meaning. If columns and datatypes do not match, your merge is not just invalid, it is conceptually confused.
-
Choose the operator based on the world you are modeling.
UNIONis for unique identities,UNION ALLis for preserving occurrences. -
Delay ranking until after combination. Sorting and limiting make sense only once you have the full merged result.
-
Before writing the query, define the question. Are you asking what exists once, or what happens many times?
The deeper lesson: data is not just combined, it is interpreted
The temptation in analytics is to believe that the right tools simply reveal the truth. But even something as technical as a set operator shows that truth depends on framing. If you collapse repeated rows, you are not making the data more correct in some absolute sense. You are choosing a model where uniqueness matters more than frequency. If you preserve all rows, you are not being more raw or more honest by default. You are choosing a model where occurrence matters more than uniqueness.
That is why these operators are more profound than they look. They force us to confront a basic fact of reasoning: the same information can be true in multiple ways, depending on whether we care about types or counts, identities or events, categories or histories.
So the next time you combine data, resist the reflex to make it tidy first. Ask what kind of truth you are after. Sometimes the repetition is the problem. Sometimes it is the message. The difference is not cosmetic. It is the difference between erasing reality and understanding it.
Sources
Hatch New Ideas with Glasp AI 🐣
Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)
Start Hatching 🐣