編集に参加したがを試してみましたが、サブカテゴリとしても
SELECT
product.id,
product.title AS product_title,
procat.title AS category_title
FROM product,
procat
WHERE product.procatid = procat.id
OR product.procatsubid = procat.id
AND product.procatid = '31'
AND product.procatsubid = '21'
を取得します。
SELECT
product.id,
product.title AS product_title,
cat.title AS category_title,
subcat.title AS subcategory_title
FROM product
INNER JOIN procat cat on product.procatid = cat.id
INNER JOIN procat subcat on product.procatsubid = subcat.id
procat
WHERE product.procatid = '31'
AND product.procatsubid = '21'
-- The below should be redundant, but I guess you can use them to ensure that the product FKs are correct and the table integrity is maintained
AND cat.parentid = 0
AND subcat.parentid <> 0
(おそらく再帰的に)(すなわち、製品はおそらくちょうどprocatサブカテゴリーで分類されなければならない、と親カテゴリIDがprocat.parentをナビゲートすることによってに到着するカテゴリに製品の外部キーに冗長性があるかもしれないようですこれで複数の値を取得しています....私は製品タイトルを取得する必要があります。私はカテゴリーIDを持っているので、タイトルとIDはサブカテゴリIDです。したがって、サブカテゴリのタイトルは実際にプロカットでカテゴリとサブカテゴリは同じ方法それらは親idですprocat idに親IDがある場合はそのサブカテゴリを意味します。そうでない場合は0 –