Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5933507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:58:58+00:00 2026-05-22T14:58:58+00:00

This is from a homework question. We solved it by building the SQL query

  • 0

This is from a homework question. We solved it by building the SQL query dynamically. But we are interested if it is possible to do with pure SQL.

A simplification of what is desired:
There is a table with two columns: source id and destination id. Given an id and a number n, we need to find all id of distance smaller equal n from the given id.

Clarification Edit:
Think about the table as representing web-links. If the row (1,3) appears in the table, it means that web-page 1 has a link to web-page 3.
We need to find all webpages that are reachable from a starting web-page with n clicks or less.

Since it is a “curiosity” question, 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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:58:59+00:00Added an answer on May 22, 2026 at 2:58 pm

    You cannot express transitive closure using relational algebra or pure old SQL, so a general solution for any N is not possible.

    The best you can do is choose the N at “compile time” and use lots of joins, as you already do in the dynamically generated query approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This IS NOT a Homework question! While building my current student database project I
yes, this is a homework-type question but could you please help me out? In
This is a homework question, I got the basics down, but I can't seem
This is a homework question from compiler design course. I just need an explanation
This is a homework question I am sorry but I am lost. What happens
This is not a homework question, but rather my intention to know if this
This question exist only because of pure curiosity. Not a homework. Find the fastest
This is a homework question, but as you can see I've written most of
I admit this is a homework question that asks if this is possible. I
Possible Duplicate: How to find positions of the list maximum? A question from homework:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.