This is from a household question. We solved this by building the SQL query dynamically. But we are wondering if this is possible with pure SQL.
Simplification of the desired: There is a table with two columns: a source identifier and a destination identifier. Given id and number n, we need to find all id of a distance less than n from a given id.
Editing explanations:
Think about how a table is a web link. If row (1,3) appears in the table, this means that web page 1 has a link to web page 3.
We need to find all web pages accessible from the initial web page with n clicks or less.
Since this is a matter of βcuriosity,β use whatever SQL implementation you prefer. "Pure SQL" means everything that fits into the "structured query style." Using loops is not considered "pure SQL" (for the sake of the question).
source
share