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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:48:56+00:00 2026-06-07T04:48:56+00:00

OK this is getting confusing so I decided to write a new question. I

  • 0

OK this is getting confusing so I decided to write a new question.

I need to check if a row in my category table is a child category. I then need to check which parent category the child is part of?

A parent category has a categoryID and a ParentCategoryID of 0
A child category has a categoryID and a ParentCategoryID eg 30.

Category Table:

ID PCID NAME
10  0   Computers
11  10  Software
12  10  Hardware

This is what Ive tried:

This will display the parent categories(because PCID 0 is the parent):

SELECT        CategoryID, ParentCategoryID, Name, Published, Deleted, PictureID
FROM          Nop_Category
WHERE        (Deleted = 0) 
AND          (Published = 1) 
AND          (ParentCategoryID = 0)
  • 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-07T04:48:58+00:00Added an answer on June 7, 2026 at 4:48 am

    Self join back to the table to find the actual parent of child.

    SELECT        c1.CategoryID, c2.ParentCategoryID, c1.Name, c2.Name as ParentName, c1.Published, c1.Deleted, c1.PictureID
    FROM          Nop_Category c1
    JOIN          Nop_Category c2 on c1.ParentCategoryId = c2.CategoryId
    WHERE        (c1.Deleted = 0)  
    AND          (c1.Published = 1)  
    AND          (c1.ParentCategoryID = 10)
    

    This would return both children of the category “Computers”. Is that what you’re looking for?

    Of course, you can turn this around to display all the children of a specific parent or from all parents:

    SELECT c.*, p.* -- shortened, but you should pick specific columns
    
    FROM Nop_Category p -- parent
    JOIN Nop_Category c ON c.ParentCategoryId = p.CategoryId -- children
    
    WHERE p.ParentCategoryId = 0 -- all top level parents
    
    
    SELECT c.*, p.* -- shortened, but you should pick specific columns
    
    FROM Nop_Category p -- parent
    JOIN Nop_Category c ON c.ParentCategoryId = p.CategoryId -- children
    
    WHERE p.CategoryId = 10 -- only the "Computers" category
    

    Or, if you just want the children of category “Computers”, change your ParentCategoryId to 10

    SELECT        CategoryID, ParentCategoryID, Name, Published, Deleted, PictureID  
    FROM          Nop_Category  
    WHERE        (Deleted = 0)   
    AND          (Published = 1)   
    AND          (ParentCategoryID = 10)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to java so this is a bit confusing I want to get
I'm new to Git and this is really confusing. I wanted to start off
I am getting this rather confusing compiler warning: [DCC Warning] W1056 Warning: Duplicate resource:
This is my first time using the Entity Framework and I'm getting some confusing
This is my check-box and it's created dynamically by getting the value of the
While consuming SOAP service, I am getting this error. I just dun get it
This is getting me quite confused: I have a small application that uses a
Getting this out of the way; I don't frequently do much in php or
Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
Am getting this error message and matched my brackets and couldn't find anything wrong.

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.