Avatar of techpr0
techpr0
Flag for United States of America

asked on 

Help with sql statement.

I need help creating a sql statement. Given the below 2 tables. I am aware that this would have been easier if a subcategory table would have been created instead of stroring the categories and subcategories together.

Table Category
intID     catParentID     CatName
1                NULL          Name 1
2                NULL          Name 2
3                NULL          Name 3
5                   2             Name 4
7                   2             Name 5
8                   1             Name 6


Table Products
IntID          catID       ProductName
1                   8                Prd 1
2                   8                Prd 2
3                   5                Prd 3
4                   7                Prd 4
5                   1                Prd 5
6                   3                Prd 6

So if i select intID 1 from the category table it will return Prd 1, Prd 2, and Prd 5 from the products table.

So if i select intID 2 from the category table it will return Prd 3 and Prd 4 from the products table.

So if i select intID 3 from the category table it will return Prd 6 from the products table.

Microsoft SQL Server 2008Microsoft SQL Server 2005

Avatar of undefined
Last Comment
techpr0

8/22/2022 - Mon