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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:15:43+00:00 2026-06-03T06:15:43+00:00

I have a problem with retrieve column values like depending on other column I

  • 0

I have a problem with retrieve column values like depending on other column
I tried to do it with outer join and nested select but I think I can’t find the solution in my head

Categories Table:
ID  Name                ParentID
--------------------------------
1   Software            NULL
2   Domains             NULL
3   Games               NULL
4   Accounts            NULL
5   Others              NULL
6   Security Software   1
7   Operating Systems   1
8   Browsers            1
9   Developer Tools     1
10  .com Domains        2
11  .net Domains        2
12  .org Domains        2
13  Online Games        3
14  PC Games            3
15  PS Games            3
16  RapidShare Accounts 4
17  4shared Account     4
18  Web Templates       5
19  Flash Intros        5
20  Firewall            6
21  Antivirus           6

What I want do to display parent category name
instead of parentID

Like that

ID  Name                ParentID
--------------------------------
1   Software            NULL
2   Domains             NULL
3   Games               NULL
4   Accounts            NULL
5   Others              NULL
6   Security Software   Software
7   Operating Systems   Software
8   Browsers            Software
9   Developer Tools     Software
10  .com Domains        Domains
11  .net Domains        Domains
12  .org Domains        Domains
13  Online Games        Games               
14  PC Games            Games               
15  PS Games            Games               
16  RapidShare Accounts Accounts            
17  4shared Account     Accounts            
18  Web Templates       Others              
19  Flash Intros        Others              
20  Firewall            Security Software
21  Antivirus           Security Software
  • 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-03T06:15:45+00:00Added an answer on June 3, 2026 at 6:15 am

    you need to join on the table two times

    SELECT c1.Id, c1.Name as parentname , c2.name
    FROM categories c1
    JOIN categories c2
        ON c1.id = c2.parentid
    

    the results will be:

    ID      ParentName            Name
    1       software              security software
    1       software              operating software
    2       domains               .com domains
    2       domains               .net domains
    2       domains               .org domains
    3       games                 pc games
    

    which will give you the parentID, parentName and Name of the subcategory or child.

    You can also change it to include the subcategory id, if needed.

    Based on your Edit you can use the following:

    create table categories
    (
        id int,
        name varchar(50),
        parentid int
    )
    
    insert into categories values(1, 'software', null)
    insert into categories values(2, 'domains', null)
    insert into categories values(3, 'games', null)
    insert into categories values(6, 'security software', 1)
    insert into categories values(7, 'operating systems', 1)
    insert into categories values(8, 'browsers', 1)
    insert into categories values(10, '.com domains', 2)
    insert into categories values(11, '.net domains', 2)
    insert into categories values(12, '.org domains', 2)
    insert into categories values(13, 'online games', 3)
    insert into categories values(14, 'pc games', 3)
    insert into categories values(15, 'ps games', 3)
    
    select c1.id
        , c1.name
        , (select name from categories where c1.parentid = categories.id) as ParentId
    from categories c1
    

    which will result in:

    enter image description here

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

Sidebar

Related Questions

I have next problem, when I'm trying to retrieve value from xforms:select elements I
I have a serious problem. Firstly, I am trying to retrieve values from my
I am facing a problem while using Select statement where I have a column
I have a problem with getting jquery to retrieve results from a WCF service.
I have problem with cakephp's Session->write method. If I set a value like $_SESSION['..']
I have posted this problem yesterday..but unfortunately, no one has given me the solution
I have a problem with the Elixir declarative layer; I want to retrieve, for
So say I have a node structure like: <Row> <Column Name=Primary Number>1</Column> <Column Name=Secondary
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run

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.