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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:20:06+00:00 2026-05-27T23:20:06+00:00

I have records with a project id and an ‘inherit id’, i.e. the project

  • 0

I have records with a project id and an ‘inherit id’, i.e. the project that the current project inherits from. The inheritance level is unknown.

I now need to collapse this to: ‘inherit from the top most’

E.g.:

1006 <- 1005 <- 1002 <- 999

prj_id / inherit_id

999  / 1002

1002 / 1005

1005 / 1006

should collapse to

1006 <- 1005 

1006 <- 1002

1006 <- 999

prj_id / inherit_id

999  / 1006

1002 / 1006

1005 / 1006

Can this be done in SQL statement without loops?
Creating temporary tables is fine.
It should work for FireBird, SQL Server, Oracle 9+ (i.e. 3 sets of statements is fine)

I only got this far:

Records that inherit from a record that itself inherits again:

select tt_prj_id,tt_name,tt_inherit_id from tt_prj a

where a.tt_inherit_id in

(select tt_prj_id from tt_prj b

 where b.tt_inherit_id is not null

 and b.tt_inherit_id > 0)

Who can help me further?

  • 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-27T23:20:07+00:00Added an answer on May 27, 2026 at 11:20 pm

    Something like the following should get you started (it’s not the final solution!):

    with recursive project_tree as (
       select tt_prj_id, cast(tt_prj_id as varchar(500))||'/' as id_path, tt_prj_id as root_id
       from tt_prj
       where tt_inherit_id = 0
    
       union all
    
       select c.tt_prj_id, id_path || cast(c.tt_prj_id as varchar(100)) ||'/', null
       from tt_prj c
         join project_tree p on c.tt_inherit_id = p.tt_prj_id
    )
    select *
    from project_tree;
    

    This works Firebird 2.5 (might also work with 2.1, but I don’t have one at hand right now)

    It should work with SQL Server when you remove the keyword recursive (which is required by the ANSI standard, but since when did Microsoft care about that…) and you need to replace the standard string concatention || with the + operator.

    Oracle does only support recursive CTEs before 11.2.
    In prior version you need to rewrite this using CONNECT BY, which woudl be something like this:

    select tt_prj_id, tt_inherit_id, sys_connect_by_path(tt_prj_id, '/')
    from tt_prj
    start with tt_inherit_id = 0
    connect by prior tt_prj_id = tt_inherit_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our project we have a requirement that when a set of records are
I have following records in text file, need to extract that record form text
I need to find all the records that have no associated records in any
I have a project where I need to pull in a lot of records
I have made one sample project which can add and edit records from SQLite
So I have a typed dataset that I have created records for from another
I have a project that uses JMF, and records for a short time (a
I have a table that hold records of part numbers for a specific project
In my A-Level project I have all the record info stored in an MS
I have records in the database with the sort order number. Now I want

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.