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 6357363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:09:02+00:00 2026-05-24T23:09:02+00:00

I have a need to store a structure where N parents will have 1

  • 0

I have a need to store a structure where N parents will have 1 to N children and each child will have 1 to N children. I would like to store this in a db in a manner that is both relatively performant and highly extensible w/o requiring db schema changes.

Each parent must be unique and N parents might have the same child. However, that child may have different children depending on the parent. (clear as mud?)

It may be easier to describe this as parentA may have a male child that has certain attributes (brown hair, brown eyes). parentb also has a male child but this child has blonde hair and blue eyes. I need to store each of these children (male and female) and each attribute (hair and eye color) in a normalized fashion and relate them in such a way that when I query parenta I get al of their children and those childrens attributes.

I have done a bit with tree structures and hierachical structures in SQL but am having a hard time conceptualizing this particular scenario in a manner that meets my requirements of performance and extensibility. Children and associated attributes will be added at regular (if not frequent) intervals.
Thanks in advance. I know clarification will be required.

Additional clarification

Ok, it appears a different example may be needed. Let’s use the good-old example of a car.

CarA and CarB both have steering wheels, engines, and tires. CarA’s steering wheel has radio controls on it. CarB’s steering wheel does not. CarA has a six cylinder motor and CarB has an eight cylander motor. I need to model the relationship between each car and each feature with that feature’s attribute. Am I helping at all?
-rb

  • 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-24T23:09:03+00:00Added an answer on May 24, 2026 at 11:09 pm

    if this is fixed at three layers and they are conceptually distinct (as in your extended example) then i think you are being confused by the idea of trees where they are not necessary. just use tables and relations as you would with any other problem.

    • a table for parents
    • a table for children (if they have always exactly two parents, parents can be fields, otherwise you also need a table for the relationship)
    • a table for attributes and another for the many-to-many relationship between that and children [or store these in the children table – see comment from DForck42 below]

    trees are necessary where the nodes at different levels are “the same thing”. but they’re not a great fit with sql, so i wouldn’t try to use them where they don’t seem to be necessary.


    update. from your comments below i think that you are saying that children are divided into classes or types, and that the possible attributes depends on the type of the child, but that the values of those attributes depends on the parent.

    in that case you have a completely different problem, more like OO inheritance. the simplest solution that i see is that you can have a different table for each kind of child. then each table has different columns for the different attributes. child tables refer to parent tables.

    so you would have a parent table with IDs. then you might have a child table for “admin sites”. each row of that child table would reference a parent via the ID and contain URL, CSS, etc as columns. another child type, like “database config page” would be in another table, with a different set of attributes.

    if you have attributes in common then you can either repeat them in each table or have a “superclass” table.

    solutions like this can get quite complicated and i’d suggest asking another question once you have a clearer explanation of what you want. there’s a good explanation of the options here – http://www.sqlalchemy.org/docs/orm/inheritance.html (ignore the parts relevant to SQLAlchemy and just look at how they are using tables in different ways to model inheritance).

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

Sidebar

Related Questions

I have id values for products that I need store. Right now they are
I have some things in my app that I need to store, in order
I have values that are 64-bit unsigned ints, and I need to store them
I have something like Facebook's Wall build on PHP that uses MySQL database. Structure:
I'm designing an application that will use Oracle , and we have this department
I have a situation where I need to store a graph data structure in
I have a data structure something like this: typedef struct tagSUB_DATA { double measuredValue;
I have a need to store an ordered list of strings and am trying
I am developing a geneology application, and I have a need to store dates
I have a program in which I need to store a Class object into

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.