-1

CategoryID(1) を取得したい ; そのサブカテゴリ (2) がコンテンツ テーブルにある場合。

つまり、contenttable から categoryid (2) を取得します。カテゴリテーブルでそのparentid(1)を見つけます。上部のカテゴリ行 (categoryid:1) を選択 - コンテンツの上部のカテゴリ行を選択できませんでした。どうすればこれを作成できますか?

カテゴリ表:

CategoryID , ParentID
    1            0
    2            1

コンテンツテーブル:

  _id, CategoryID
  ...       2 

コード:

   SELECT DISTINCT contenttable.CategoryID, categorytable.CategoryID FROM categorytable 
                    INNER JOIN contenttable 
                    ON categorytable.CategoryID = contenttable.CategoryID
4

2 に答える 2

1
SELECT parent.CategoryID
FROM categorytable AS parent
JOIN categorytable AS child ON child.ParentID = parent.CategoryID
JOIN contenttable           ON child.CategoryID = contenttable.CategoryID
于 2013-04-26T07:30:02.930 に答える
-1

あなたの質問はまだ不明です。これはあなたが探しているクエリですか?

select CategoryID.categorytable from categorytable where CategoryID.categorytable=(select ParentID.categorytable from categorytable where CategoryID.categorytable=(select CategoryID.contenttable from contenttable));
于 2013-04-26T07:21:42.297 に答える