← SQL workplace practice

Recursive structures · Original fictional data · Free files and full answers

Identify direct graph edges with an alternate route

An edge is redundant when a path from its src to dst exists after removing that exact edge. Return src,dst sorted. The alternate path must have at least two edges.

Use this fixed business case to build a checked CSV and a replayable SQL handoff. No account required. Scenario datasets are shared across related exercises; each exercise has its own decision and output contract.

Your output contract

  1. An edge is redundant when a path from its src to dst exists after removing that exact edge. Return src,dst sorted. The alternate path must have at least two edges.
  2. Return exactly the declared columns and order. Money uses integer cents; all time values are elapsed UTC minutes unless a field is explicitly a day index. NULL is unknown and differs from numeric zero.
  3. These are original fictional records and exercise policies. All source tables in this case are included in the downloadable pack.

Return columns exactly as src, dst. Sort order follows the task. Output has 3 rows; an empty CSV field means NULL.

Source data

nodes

10 source rows · Download nodes CSV

id INTEGERparent INTEGERcost INTEGER
1NULL5
2110
3120
423
524
638
742
8NULL6
989
1091

edges

8 source rows · Download edges CSV

src INTEGERdst INTEGERweight INTEGER
123
138
232
247
341
422
454
671

parts

6 source rows · Download parts CSV

parent TEXTchild TEXTqty INTEGER
KITFRAME1
KITWHEEL2
FRAMEBOLT4
FRAMEBAR2
WHEELBOLT3
WHEELRIM1
Field dictionary and schema
nodes:
  id INTEGER — Stable record or business key; retain its declared type.
  parent INTEGER — Exact integer measurement; use the task rule for units and ordering.
  cost INTEGER — Exact integer measurement; use the task rule for units and ordering.

edges:
  src INTEGER — Exact integer measurement; use the task rule for units and ordering.
  dst INTEGER — Exact integer measurement; use the task rule for units and ordering.
  weight INTEGER — Exact integer measurement; use the task rule for units and ordering.

parts:
  parent TEXT — Literal text label or key; comparisons use SQLite binary text semantics.
  child TEXT — Literal text label or key; comparisons use SQLite binary text semantics.
  qty INTEGER — Exact integer measurement; use the task rule for units and ordering.

Download complete SQLite setup

A method you can reuse

  1. An edge is redundant when a path from its src to dst exists after removing that exact edge. Return src,dst sorted. The alternate path must have at least two edges.
  2. Inspect the source grain, keys and ties before writing the query. Use the worked SQL and complete expected CSV to review any mismatch.

Watch for this wrong turn

Reachability using the original graph trivially finds the same direct edge and labels every edge redundant.

Run and check in SQLite

Your SQL runs locally in the existing SQLite worker. The checker compares every column, row, type, value and row order with this fixed output. It accepts equivalent SELECT or WITH queries. Browser storage keeps your SQL on this device when available.

Complete worked SQL and expected output
WITH RECURSIVE p(a,b,node,path,depth) AS (SELECT src,dst,src,','||src||',',0 FROM edges UNION ALL SELECT p.a,p.b,e.dst,p.path||e.dst||',',p.depth+1 FROM p JOIN edges e ON e.src=p.node WHERE NOT(e.src=p.a AND e.dst=p.b) AND instr(p.path,','||e.dst||',')=0) SELECT DISTINCT a src,b dst FROM p WHERE node=b AND depth>=2 ORDER BY src,dst;
"src","dst"
"1","2"
"1","3"
"2","4"
Reference SQL · Complete expected CSV · Empty answer CSV

Choose another SQL task · Original data exception cases · Larger workplace projects