Why Ordering Is an Argument, Not a Fact

Kai Nguyen

Hatched by Kai Nguyen

May 05, 2026

9 min read

84%

0

The hidden question behind every query and every graph

What comes first: the thing with no dependencies, or the thing you happen to ask for first?

That sounds like a technical question, but it is really a philosophical one. In graphs, a topological sort gives a linear ordering of elements that depend on one another, starting from nodes with no incoming edges, the sources, and ending with nodes that have no outgoing edges, the sinks. In SQL, by contrast, rows in a table are not ordered in any particular way unless you explicitly ask for an ordering with ORDER BY. Even then, the WHERE clause filters truth first, while DISTINCT strips away duplicates before you ever see the final shape of the result.

The deeper tension is this: human beings crave order, but systems only guarantee structure. If you do not ask carefully, the system will still answer, but it may answer in the wrong dimension. A graph asks, “What must precede what?” A database asks, “Which rows satisfy the condition?” These are not the same question, yet both expose the same habit of mind: we often confuse the existence of data with the existence of a meaningful arrangement.

The real skill is not just retrieving information. It is recognizing when order is inherent, when it is imposed, and when it is merely assumed.


Dependencies are not sequence, and sequence is not meaning

A topological sort is a reminder that some things cannot happen until other things happen first. You do not pour the roof before you build the walls. You do not run a deployment before the tests pass. In that sense, a graph of dependencies is an honesty machine. It refuses to let you pretend that all steps are interchangeable.

SQL, on the other hand, can make the opposite illusion feel natural. You ask for rows, and without ORDER BY, you may still get them in some consistent-looking sequence. But that sequence is incidental, not contractual. The table is not a line, it is a set of records. Unless you specify a criterion, the database is free to return rows in whatever order is convenient.

This difference matters because humans constantly infer causality from adjacency. If a row appears first, we assume it is somehow primary. If a task is listed above another, we assume it should happen earlier. Yet the actual logic may be more subtle: the first visible item may simply be the latest, the rarest, or the one with no duplicates after DISTINCT has done its work.

Order has three different meanings that we often collapse into one: dependency order, display order, and discovery order.

When these are mixed up, mistakes follow. A project team may treat a dashboard sorted by recency as if it were sorted by importance. A developer may assume a table’s current output order is stable. A student may think a “source” node in a graph is a starting point because it appears first, when in fact it is first because it has no prerequisites. The direction of explanation has been reversed.

The crucial insight is that order is not a property of data alone. It emerges from the relationship between data, constraints, and the question being asked.


The database and the graph are both truth filters

At first glance, topological sorting and SQL retrieval seem unrelated. One belongs to graph theory, the other to database querying. But both are really about making structure visible without distorting it.

A topological sort does not invent dependencies. It reveals a possible linearization that respects them. If there is a cycle, the illusion of a clean ordering collapses, because no valid sequence exists. That is a powerful lesson: sometimes the obstacle is not complexity, but contradiction.

SQL behaves similarly in a different register. The WHERE clause is a Boolean filter. It does not sort, rank, or interpret. It asks whether a row is true relative to a condition. DISTINCT then removes repeated values, forcing the result to express uniqueness rather than accidental repetition. ORDER BY finally gives shape to the output, but only after truth and uniqueness have been established.

This sequence, filter first, shape second, is more than a database trick. It is a general epistemic discipline.

  1. Establish membership: what belongs here at all?
  2. Remove noise: what is repeated, irrelevant, or misleading?
  3. Impose ordering: what sequence best serves the purpose?

That is exactly how good reasoning works. You do not begin by sorting opinions. You begin by deciding which claims qualify as relevant, which are redundant, and which structure reveals the underlying dependencies.

Think of a hiring process. If you sort candidates by charisma before you establish basic qualifications, you have mistaken presentation for fit. Think of medical triage. If you rank patients before filtering for urgency, you have confused aesthetics with survival. In both cases, the structure of the decision matters more than the final list.

A query is never just a query. It is an argument about what reality should count.


Sources, sinks, and why every system has entry points and endpoints

The language of graphs offers a useful vocabulary for thinking about systems more broadly. A source node has no incoming edges and only outgoing edges. A sink node has only incoming edges and no outgoing edges. These are not just technical definitions, they are structural roles.

A source is something that can begin without needing permission from anything else. A sink is something that can be completed without demanding further action. In a project, sources are the prerequisites, the inputs, the foundations. Sinks are the outputs, the deliverables, the closure points. In a database workflow, the source may be the set of raw rows, while the sink may be the final report after filtering, deduplication, and ordering.

This is where the analogy becomes especially useful. Many organizations obsess over sinks. They care about polished presentations, charts, rankings, and final dashboards. But a topological view asks us to look upstream. What are the source conditions that make the output possible? Which dependencies have to be satisfied before the result can even exist?

Likewise, many people misuse ORDER BY as a way to create meaning where none has been established. Sorting by publication year can be useful, but it does not tell you whether the books are relevant, distinct, or even comparable. If the underlying selection is poor, the most elegant ordering only beautifies confusion.

A better metaphor is a river system. Sources are springs, tributaries, and snowmelt. Sinks are lakes, deltas, and seas. You can stare at the mouth of the river and learn something, but you will understand much more if you trace the flow back to its origins. Topological thinking and careful SQL both teach the same habit: trace structure backward before you present it forward.

The beginning of wisdom is not asking, “What is first?” It is asking, “What must already be true for anything to come next?”

That question transforms how you work with data, projects, and ideas. It moves you from surface sequence to causal architecture.


How to think like a topological sorter when writing queries, plans, or decisions

The most useful synthesis here is not a new definition, but a new mental model. When confronted with any ordered output, ask whether the order is doing one of three jobs:

  • Respecting dependency: one thing must logically precede another.
  • Clarifying relevance: some items should be filtered in or out.
  • Making comparison possible: once the set is correct, order helps the eye compare.

If you skip the first job, you risk producing an impossible plan. If you skip the second, you clutter the result with noise. If you skip the third, you may have truth but not usability.

This is why strong systems separate concerns. In SQL, WHERE is not ORDER BY, and DISTINCT is not WHERE. Each stage answers a different question. In graphs, sources are not sinks, and linear order is not the same as causal order. Each concept preserves a different kind of truth.

Here is a practical framework that follows from this:

1. Ask what kind of order you need

Not all orderings are equal. A chronological list, a dependency chain, a ranking, and a deduplicated set all answer different questions. Before sorting anything, name the purpose of the order.

2. Filter before you beautify

If a row or task does not belong, no amount of sorting will fix it. Use the equivalent of a WHERE clause in your thinking: what conditions must be true before this item deserves attention?

3. Remove duplicates before drawing conclusions

Repeated values can create false confidence. DISTINCT is not merely a database keyword. It is a reminder that repetition can masquerade as importance. Ask what is genuinely unique before you infer trends.

4. Respect dependencies before preferences

A topological sort is a discipline of humility. It forces you to accept that not everything is equally free. In planning, writing, debugging, and learning, some steps are sources and others are sinks. Identify them.

5. Treat output order as a design decision, not a default

If you care about how a result will be interpreted, specify the order explicitly. Never assume that what comes back is the meaningful sequence unless you demanded that sequence.

This framework scales beyond code. It applies to note taking, research, hiring, prioritization, and even self management. Your mind, like a database or a graph, is better when it separates truth selection from truth presentation.


Key Takeaways

  • Do not confuse data with order. A table can contain rows without implying any natural sequence.
  • Filter first, then sort. In reasoning, as in SQL, relevance comes before arrangement.
  • Dependencies are a different kind of order. Topological sorting captures what must precede what, not what looks important.
  • Duplicates can distort judgment. DISTINCT is a reminder to ask what is actually unique, not merely repeated.
  • Always specify the kind of order you want. Whether you are querying data or planning work, make the ordering rule explicit.

The real lesson: reality does not owe you a neat line

We are drawn to sequences because they feel intelligible. A numbered list looks cleaner than a tangled web. A sorted table looks more trustworthy than an unordered pile. But both graphs and databases expose a harder truth: reality often arrives as structure before it arrives as sequence.

A topological sort respects hidden constraints. SQL makes you state your conditions. Together, they teach a discipline that is surprisingly rare: do not ask the world to be simple before you have made your question precise.

That is why ordering is not a mere presentation choice. It is an act of interpretation. Every time you choose a filter, a sort, a deduplication rule, or a dependency order, you are declaring what kind of world you think you are in. And the more carefully you make that declaration, the less likely you are to mistake noise for truth, sequence for causality, or appearance for meaning.

Sources

← Back to Library

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 🐣