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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:13:33+00:00 2026-06-15T08:13:33+00:00

I have this 4 level user table as below user_id parent_id 1 NULL 2

  • 0

I have this 4 level user table as below

user_id parent_id
1       NULL
2       1
3       2
4       2
5       3
6       1

I would like to select all user under a certain parent id, for example, user_id = 1 and in this case shall return result like below:

user_id  parent_id
2        1         // return because parent_id = 1
6        1         // return because parent_id = 1
3        2         // return because parent_id of 2 is 1
4        2         // return because parent_id of 2 is 1
5        3         // return because parent_id of 3 is 2

By providing an id, what would be the query?

Thanks in advance!

  • 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-06-15T08:13:34+00:00Added an answer on June 15, 2026 at 8:13 am

    Try this ::

        Select 
    user_id 
    from 
    
    my_table 
    where parent_id in 
    (
    Select 
    user_id 
    from my_table where parent_id in 
    (Select user_id from my_table where parent_id in(Select user_id from my_table where parent_id =?)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation like this. I have schema which has high level user
i have a text like this .... ======== 1079.tif Image Description : Vexcel-UCD-Level-3 ------------------
I have a class level price variable decalred inside a page, like this: public
I'm using MySQL. This is table i have Level Programmingtime Clientname projectid 0 128
Let's say we have a table with user comments. First-level comments have a reference
I have the two tables below. The table jobs will have a user id
I've modified my devise table, User, to have a clearance column. This column is
I have this error message: Msg 8134, Level 16, State 1, Line 1 Divide
I have this reqular ul > li structure <ul class='compare'> <li>Level 1 <ul> <li>Level
I just noticed something strange. If I have this XML: <level number=7 background=background_5> and

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.