Link to home
Start Free TrialLog in
Avatar of Dhanasekaran Sengodan
Dhanasekaran SengodanFlag for India

asked on

Get Subcategories count from Category table in T-SQL

Hello Dear Coders,

 

I have a table which i save my all categories info with Parent Category Info. Let's go on a sample.

 

CatID           CatName              MainCatID

-------------------------------------------------------------

1                  Electronics             0

2                  Cell Phones            1

3                  PDAs                     1

4                  Nokia                     2

5                  N73                       4

6                  Sony Ericsoon        2

7                  K700i                     6

.

.

.

 

 

Now,

 

As you guess MainCatID = 0 cats are Main Cats.

 

I need to list Electronics Sub Categories in SQL with a simple query. I don't want to use Cursor or Table (Not TempTable).

 

something like Select CatID from Categories Where MainCatID In (1,2,4,6)  -- How can find the elecktronic sub categories?

 

Thanks in advance.
Avatar of seenuforall
seenuforall
Flag of India image

Select CatId from categories(sub categroy table) a, category(maincategory table) b
where a. MainCatID = b.MainCatID

SOLUTION
Avatar of seenuforall
seenuforall
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial