0

I have 2 tables like these:

category table

id       category_title      category_parent
----     --------------      ---------------
 1          sport                   0
 2        electronic                0
 3         football                 1
 4        volleyball                1
 5         laptop                   2
 6        television                2
 7        basketball                1

product table

 id       product_name       product_category(referenced to id column from category table)
----     --------------      ---------------
 1         product1                 3
 2         product2                 3
 3         product3                 4
 4         product4                 4
 5         product5                 5
 6         product6                 6
 7         product7                 7

I want to get all products in a main category (for example I want to get all products from product table that their category is sub-category of sport). what is the right SQL query? (for example I want to get these products: product1, product2, product3, product4, product7 that are in football, volleyball, basketball categories. These categories are sub category of sport. So I want to get all products with sport category!)

Atefeh
  • 11
  • 2
  • Please include what is your desire result with this data sample so we get a better idea what query you need. Please read http://stackoverflow.com/help/how-to-ask Here is a great place to [**START**](http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum/) – Juan Carlos Oropeza Feb 06 '16 at 11:39
  • I want a SQL query that returns all products which have different categories. But these categories have same category_parent. – Atefeh Feb 06 '16 at 11:48
  • I know, but I cant translate those words in a query result. So if you create a similar table as the one you already have will help a lot. – Juan Carlos Oropeza Feb 06 '16 at 11:49

0 Answers0