テーブルからdistinct(tr.item_id)を選択しようとしていますterm_relationships
。多くのタグに関連している場合は、投稿を2回リストすることは避けたいと思います。
誰かが私を正しい方向に向けることができますか?
クエリ:
tag_inject = "tr.taxonomy_id = 94 or tr.taxonomy_id = 92 or tr.taxonomy_id = 93"
SELECT * FROM term_relationships tr" + _
" INNER JOIN term_taxonomy tax ON tr.taxonomy_id = tax.taxonomy_id" + _
" INNER JOIN post po ON tr.item_id = po.post_id" + _
" where tr.cpa_id = " & cpa_id & " and (" & tag_inject & ")" + _
" and po.cpa_id = " & cpa_id & " and po.post_status = 1" + _
" order by po.post_start_date desc limit " & amount_1
コメント欄が小さすぎて6時間待ちたくなかったのでここで答えます
みんなありがとう、
1つのクエリですべてを実行しようとしましたが、item_idを区別する必要がある場合、それは不可能だと思いますか?
そこで、個別のアイテムリストを取得した後、サブクエリを使用して投稿データを取得することにしました。
このようなもの:
sql_tags = "SELECT distinct tr.item_id" + _
" FROM term_relationships tr" + _
" INNER JOIN term_taxonomy tax ON tr.taxonomy_id = tax.taxonomy_id" + _
" INNER JOIN post po ON tr.item_id = po.post_id" + _
" where tr.cpa_id = " & clng(cpa_id) & " and (" & tag_inject & ")" + _
" and po.cpa_id = " & clng(cpa_id) & " and po.post_status = 1" + _
" order by po.post_start_date desc limit " & clng(content_amount_1)
set rs_plist = conn.execute(sql_tags)
その後..
while not rs_plist.eof
get_item_id = rs_plist("item_id")
sql = "select rec_id, post_id, post_title, post_line_desc, post_image_1, post_image_1_width from " & app_database & ".post" + _
" where cpa_id = " & clng(cpa_id) & " and post_id = " & get_item_id
set rs_post = conn.execute(sql)
..等々..
より良い代替案はありますか、それともこれがそれを行う方法ですか?