我正在尝试从 table 中选择 distinct(tr.item_id) term_relationships
。如果帖子与许多标签相关,我想避免两次列出帖子。
有人能指出我正确的方向吗?
查询:
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 个小时
多谢你们,
我试图在一个查询中完成整个事情,但是当我需要不同的 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)
..等等..
有没有更好的选择,或者这是这样做的方式?