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

  • Home
  • SEARCH
  • 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 7180377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:20:03+00:00 2026-05-28T17:20:03+00:00

I am working on a project where I need to have data inherit at

  • 0

I am working on a project where I need to have data inherit at variable depths, and then be able to return any descendants of a particular piece of data. I am working with geographical regions, so I was thinking about having a “Region” table, and have everything from “North America” to individual neighborhoods such as “Bronx”. So, if someone types in “North America”, they should also receive results for “Bronx” because “Bronx” is a descendant of “North America” by means of the relationship
North America->United States->New York(State)->New York(City)->Bronx

In my DB I was planning on having the Region table link back to itself with a table that specifies a parent/child relationship between Regions. Here is an example of what I would propose:
enter image description here

Any help would be greatly appreciated!

  • 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-28T17:20:04+00:00Added an answer on May 28, 2026 at 5:20 pm

    Do you dont need a new table. A foreign key in major table is enough.

    This is my approach:

    First problem, design data schema: I keep hierarchis with a foreign key to parent row. It is simply. You have an example with hiererchy regions here:

    WOE_ID  ISO Name    Language    PlaceType   Parent_ID
    20069843    "NA"    "Oshana"    ENG State   23424987
    55921113    "NA"    "Ondangwa"  ENG County  20069843
    ...
    

    Second problem, retrieve ascendants/descendants: As you explain, problems comes with select: select some region and all descendants os ascendants. To solve this you should to create a new tree table. This table contains pairs: al combination to a person with all they ancestors (and itself):

    region( id, name, id_parent)
    region_tree( id, id_ancestor, distance )
    

    Noticie that with this structure is easy to query hierarchies. Sample: all descendants of some region:

    select region.*, distance
    from 
      region p
        inner join 
      region_tree t 
        on ( p.id = t.id)
    where
      id_ancesor = **someregion.id **
    

    You can play with distance to get only sub-regions, sub-sub-regions, …

    Last problem, keep tree: tree must be all time up to data. You should automatize this: a trigger over region or a store procedure for CRUD operations,

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

Sidebar

Related Questions

I have a project that I'm working on and I need to be able
I'm working on a project where we need to have data entered or updated
I am working on a Java project and need to have a keypress simulate
I need to have an at-home project now that I'm working on Python/Django at
We have need for a rating system in a project we are working on,
I have been working on a C# 4.0 WPF project and need to figure
I'm working on a project where I have 2 web services that need the
In the project I am currently working on, we have the need to develop
I'm working on a project where I have some hierarchical data that I want
For a project I'm working I need to have some sort of enumaration class

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.