Skip to content
Astera Technology

Why do two different route pairs count as one?

Deduplicate the actual tuple rather than a separator-free concatenation.

Download complete case notes and answer keys ↓

Prepare the report input

Original report counts distinct source/destination pairs. A→BC and AB→C are different, but both concatenate to ABC. Count rows of a DISTINCT two-column subquery; input event IDs are not the route-pair identity.

Every record and report rule below is original and fictional. Reproduce the setup in a fresh SQLite test database; input previews include every table in this small fixture.

Synthetic input: routes
idsourcedestination
1ABC
2ABC
Download editable CSV ↓
Complete CREATE and INSERT fixture
CREATE TABLE routes(id INTEGER PRIMARY KEY,source TEXT NOT NULL,destination TEXT NOT NULL); INSERT INTO routes VALUES(1,'A','BC'),(2,'AB','C');

Compare misleading and corrected results

Misleading SELECT: reproduce the defect
SELECT COUNT(DISTINCT source||destination) AS route_count FROM routes;
Literal misleading result
route_count
1
Download editable CSV ↓
Corrected SELECT
SELECT COUNT(*) AS route_count FROM (SELECT DISTINCT source,destination FROM routes);
Literal corrected result
route_count
2
Download editable CSV ↓

The misleading scalar key counts one route; the corrected tuple count is two. A separator alone also requires an escaping contract if labels may contain that separator.

Check a fresh boundary case

Delete all route events in the fresh boundary fixture. The distinct-pair count is zero.

Recreate the original setup in another fresh database, then apply the change and corrected query below. For an empty result, the table displays a labelled empty-result marker rather than a data record.

Boundary change and corrected query
DELETE FROM routes;
SELECT COUNT(*) AS route_count FROM (SELECT DISTINCT source,destination FROM routes);
Literal boundary result
route_count
0
Download editable CSV ↓

Can A→BC and AB→C be merged as the same observed route?

Show the worked answer

No. The endpoints differ; corrected count is two, and an empty input correctly returns zero.

Related resources