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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:05:05+00:00 2026-05-16T01:05:05+00:00

I’ll try to expose as clear as possible ;) Well, i need to store

  • 0

I’ll try to expose as clear as possible 😉

Well, i need to store some data that can be linket to themselves as the parent > child relationship, with no-limit deep.

My first try was:

entry_id | parent_id | value
    1    |   NULL    | Foo //foo is the grand parent
    2    |    1      | Bar //bar is child of Foo
    3    |    1      | Baz //baz too
    4    |    2      | Bho //bho is child of Bar
    5    |    4      | Som //som is child of Bho
    6    |   NULL    | Git //another grand parent
    7    |    6      | Tim //Git's child

..and so on.

This structure works, but its is impossible (or at least, i couldnt go throught) find all the Foo childs and ‘sub-childs’ with just 1 query.. this need a loop.

My goal is to have a structure optimized for SELECT query, that can give me all the relationships in one shot, something like:

 SELECT "ALL SONS OF Bar"

output:

  entry_id | parent_id | value
     1     |   NULL    |  Bar
     4     |    2      |  Bho
     5     |    4      |  Som

but this structure doesnt seem to let me do that.

Any idea?

If can matter, i’ll run on Postgresql (i thought to use array fields type, but the query wont be much fast)

Edit for the philip comment: in my specific, the data shouldnt change too often, but i’ll probably need to use this structure for other tasks similar -but not equal- where the data can be updated many many times.

As a side note, using foreign keys (or a similar behavior) will be the best (deleting one ‘father’ should delete all the childs – no orphans are allowed)

  • 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-16T01:05:06+00:00Added an answer on May 16, 2026 at 1:05 am

    I think you would benefit from reading Managing Hierarchical Data in MySQL. It tells how to turn a flat table into a hierarchy with just a couple of attributes and some housekeeping. Even if you’re not going to go that way, it’s insightful.

    For PostgreSQL you can do it with WITH RECURSIVE queries: WITH Queries (Common Table Expressions).
    You need at least version 8.4 to use them.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.