Dhanasekaran Sengodan
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
where a. MainCatID = b.MainCatID