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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:10:51+00:00 2026-05-31T21:10:51+00:00

I have this data in a table, for instance, id name parent parent_id 1

  • 0

I have this data in a table, for instance,

id      name        parent      parent_id
1       add         self        100
2       manage      null        100
3       add         10          200
4       manage      null        200
5       add         20          300
6       manage      null        300

How can I left join or inner join this table itself so I get this result below?

id      name        parent
2       manage      self
4       manage      10
6       manage      20

As you can I that I just want to query the row with the keyword of ‘manage’ but I want the column parent‘s data in add‘s row as the as in manage‘s row in the result.

Is it possible?

EDIT:

the simplified version of my actual table – system,

system_id   parent_id   type    function_name       name        main_parent         make_accessible     sort
31          30          left    main                Main        NULL                0                   1
32          31          left    page_main_add       Add         self                0                   1
33          31          left    page_main_manage    Manage      NULL                0                   2

my actual query and it is quite messy already…

SELECT 
    a.system_id,
    a.main_parent,
    b.name, 
    b.make_accessible, 
    b.sort

FROM system AS a

INNER JOIN -- self --
(
    SELECT system_id, name, make_accessible, sort
    FROM system AS s2

    LEFT JOIN -- search --
    (
    SELECT system_id AS parent_id
    FROM system AS s1
    WHERE s1.function_name = 'page'
    ) AS s1

    ON s1.parent_id = s2.parent_id

    WHERE s2.parent_id = s1.parent_id
    AND s2.system_id != s1.parent_id
    ORDER BY s2.sort ASC
) b
ON b.system_id = a.parent_id


WHERE a.function_name LIKE '%manage%'
ORDER BY b.sort ASC

result I get currently,

system_id   main_parent     name    make_accessible sort
33          NULL            Main    0                1

but I am after this,

system_id   main_parent     name    make_accessible sort
33          self            Main    0                1
  • 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-31T21:10:52+00:00Added an answer on May 31, 2026 at 9:10 pm

    You just need to reference the table twice:

    select t1.id, t1.name, t2.id, t2.name
    from TableA t1 
      inner join TableA t2
        on t1.parent_id = t2.Id
    

    Replace inner with left join if you want to see roots in the list.

    UPDATE:

    I misread your question. It seems to me that you always have two rows, manage one and add one. To get to “Add” from manage:

    select system.*, (select parent 
                        from system s2 
                       where s2.parent_id = system.parent_id 
                         and s2.name = 'add') 
                     AS parent
    from system
    where name = 'manage'
    

    Or, you might split the table into two derived tables and join them by parent_id:

    select *
      from system
      inner join
      (
         select * from system where name = 'add'
      ) s2
        on system.parent_id = s2.parent_id
      where system.name = 'manage'
    

    This will allow you to use all the columns from s2.

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

Sidebar

Related Questions

Say I have this table schema. ID AccNo Amount Say I have this data
I have this big data-entry sort of page, a table kind of layout using
I have a problem. Imagine this data model: [Person] table has: PersonId, Name1 [Tag]
I'm a bit confused on this. I have a data table structured like this:
I have a table like this: Application,Program,UsedObject It can have data like this: A,P1,ZZ
I have a table like this... CustomerID DBColumnName Data 1 FirstName Joe 1 MiddleName
I have a data tables with this type of setup. Table A AID AName
If I have a table column with data and create an index on this
I have a table with data like so: [ID, Name] 1, Bob 1, Joe
I currently have the following row in my table: course_data: user_id days <-- This

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.