SELECT count(p.product_id) as cnum, p.product_id, ps.product_category_name , ps.product_category_id , ps.product_category_parent, pd.product_category_id, pd.product_category_parent, pc.product_category_id, pc.product_category_parent FROM product as p INNER JOIN product_category as ps ON p.product_category_id=ps.product_category_id INNER JOIN product_category as pd ON pd.product_category_id=ps.product_category_parent INNER JOIN product_category as pc ON pc.product_category_id=pd.product_category_parent pd.product_category_id='$cate_id' or pd.product_category_parent='$cate_id' or pc.product_category_parent='$cate_id'