2

以下のクエリを実行して、object_id の一意の結果を取得しようとしています。Group_concat Distinst を使用するのが最も効果的であると考えました。次のクエリの where 句で、クエリの結果を変数として使用する必要があります。

以下のクエリは flyspeedsql ソフトウェアでは正常に実行されますが、php では結果が表示されないようです。

これにアプローチするより良い方法はありますか?

wordpress get_results は使用する正しい関数ですか?

何かリンク55,56,57を返す必要があります

また、このクエリの結果から、次のクエリの where 句で使用できる変数を設定するにはどうすればよいですか?

クエリ 1

      $query = ("Select
         Group_Concat(Distinct $wpdb->term_relationships.object_id)
      From
           $wpdb->term_taxonomy Inner Join
           $wpdb->term_relationships On $wpdb->term_taxonomy.term_taxonomy_id =
           $wpdb->term_relationships.term_taxonomy_id Inner Join
           $wpdb->terms On $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id
       Where
           $wpdb->terms.name = 'Honda' And
           $wpdb->term_taxonomy.taxonomy = 'brands'");

       $results = $wpdb->get_results($query);
4

1 に答える 1

1

MYSQLサブクエリについて聞いたことがありますか?

正直なところ、私はその記事全体を自分で読んだことはありませんが、1 つのクエリで必要なことを行うのに十分な概念をよく知っています (とてつもないことですが)。

Select
     $wpdb->some_other_table.some_field
From
     $wpdb->some_other_table
Where
     $wpdb->some_other_table.some_other_field = (Select
       Group_Concat(Distinct $wpdb->term_relationships.object_id)
  From
       $wpdb->term_taxonomy Inner Join
       $wpdb->term_relationships On $wpdb->term_taxonomy.term_taxonomy_id =
       $wpdb->term_relationships.term_taxonomy_id Inner Join
       $wpdb->terms On $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id
   Where
       $wpdb->terms.name = 'Honda' And
       $wpdb->term_taxonomy.taxonomy = 'brands');

あなたの説明はかなり曖昧なので、これがあなたのニーズに100%合うかどうかはわかりませんが、解決策であることが判明した場合、これを機能させる方法を理解できると確信しています.

于 2013-01-17T08:29:55.950 に答える