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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:57:08+00:00 2026-05-16T19:57:08+00:00

I need to return a parent child relationship from 3 tables which are for

  • 0

I need to return a parent child relationship from 3 tables which are for bottom, mid and top level respectively. Easy stuff so far, and done already:

SELECT -1 ParentID, ID + 100000 ID,  txtName Value from tblLevel1
UNION
SELECT Level1ID + 100000 ParentID, ID + 50000 ID, txtName Value from tblLevel2
UNION
SELECT Level2ID + 50000 ParentID, ID ID, txtName Value from tblLevel3

My problem is that I need to add another field that describes the path of each entry.

For the first table, it is ‘-1;{id}).
For the second table is is ‘{Level1id};{id}’.
The third table’s query should return ‘{Level1id};{Level2id};{id}’. The problem is the third one then.

The table structures are:

Level1; ID int; txtName varchar(50)

Level2; ID int; Level1ID int; txtName varchar(50)

Level3; ID int; Level2ID int; txtName varchar(50)

How do I get the full path in the query on the 3rd table (Level3)?

This is the current result

ParentID  ID       Value
-1       100001 Test company
-1       100006 Company A
-1       100007 Company B
-1       100008 The Primary Client
-1       100009 Overseas Client  1
100001  50001   Distribution
100006  50016   Attributes
100007  50018   Attributes
100008  50019   Development
100009  50029   Database
50001   1        Balance Sheet
50001   7        Cash Flow Statement
50001   10       Income Statement
50016   20       Vehicles
50016   21       Drivers
50019   33       Health
50029   29       Database
  • 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-16T19:57:08+00:00Added an answer on May 16, 2026 at 7:57 pm

    I would question your database design, as the separate table for each “level” seems like a bad idea to me. Since I don’t know all of the specifics of your application though, I’ll assume for the moment that it’s how it has to be. Also, the whole business of adding numbers to the IDs looks to me like a BIG kludge that’s going to bite you later.

    Another, more immediate and constraining problem is that it looks like you want your third result set to have a different number of columns than the first two result sets. This is simply not possible with a UNION operator.

    If you want to add another column to the first two queries then you should be able to get what you want in the third query simply by joining between the level 3 and level 2 tables to get the level 1 ID.

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

Sidebar

Related Questions

Suppose we have 2 classes, Child, and the class from which it inherits, Parent.
I am working on a table referrals which contains parent child relations I need
I need to return server time from a webservice. I've got the following code:
I need to return a full directory name from inside a specified directory that
I need to return multiple values from a ColdFusion function in an ajax callback
I have need to return multiple results from a subquery and have been unable
I have two classes with a parent-child relationship (customer&order directory&file etc) I have typedef
I have designed a Class for Parent Child relationship class Category { public string
I want the following query to return the fields in a parent child format.
I have 2 different object types stored in RavenDb, which are a parent/child type

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.