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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:39:15+00:00 2026-05-26T03:39:15+00:00

I have a table that contains my node data in a tree view. Each

  • 0

I have a table that contains my node data in a tree view.
Each node has it’s own child. Is it possible to write a single statement to get each node along with it’s children (each level sorted by a date), and their child for as many levels as exists?

- A
- B
-     F
-          L
-     G
- C
-     K
- D
-     H
-     I
-     J
- E

So the sql should return
Each node has a parentId, when the parentId is null it means the node is a top level node

- A
- B
- F
- L
- G
- C
- K
- D
- H
- I
- J
- E

EDIT:
Here is my table structure, and it’s on a sqlite file.
I really don’t care about the version or RDBMS as long as I get the correct solution I’ll convert it myself to sqlite and I’ll get it to work

Node Table
___________________
int       - nodeId
int       - parentId /*referes to nodeId of the parent*/
varchar   - title
TimeStamp - dateCreate
  • 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-26T03:39:16+00:00Added an answer on May 26, 2026 at 3:39 am

    As you say you don’t care about the DBMS (even though you use SQLite):

    This is the oracle solution:

    SELECT lpad(' ',3*level)||title as title
    FROM   your_table
    CONNECT BY PRIOR nodeId = parentId
    START WITH parentId IS NULL
    

    This is the standard ANSI SQL Solution:

    WITH RECURSIVE CatCTE (title, nodeId, parentId, lvl) as 
    (
      SELECT title, nodeId, parentId, 1 as lvl
      FROM your_table
      WHERE parentId IS NULL
    
      UNION ALL
    
      SELECT c2.title, c2.nodeId, c2.parentId, CatCTE.lvl + 1
      FROM your_table c2 
        INNER JOIN CatCTE ON CatCTE.nodeId = c2.parentId
    )
    SELECT lpad(' ',3*level)||title as title
    FROM CatCTE
    

    (The only non-standard construct in there is the lpad function which is highly DBMS specific).

    But I don’t think you’ll be able to “convert” either solution to SQlite

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

Sidebar

Related Questions

I have a table that contains a column that is XML data type. I
I have a table that contains procedure codes among other data (let's call it
I have a table that contains a tree in oracle. MY_TABLE node_id parent_id How
I have a table that contains a column named views. Each time the user
I have a table that contains tasks and I want to give these an
I have a table that contains maybe 10k to 100k rows and I need
I have a table that contains some blob fields that I don't want to
I have a table that contains intervals: CREATE TABLE tbl ( user_id: INTEGER, start:
I have a table that contains id, created, user_id. I'm wondering if there is
I have a table that contains members names and a field with multiple ID

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.