gpt4 book ai didi

mysql - 选择带有术语 ID 的帖子

转载 作者:行者123 更新时间:2023-11-30 01:37:56 25 4
gpt4 key购买 nike

我遇到的情况是,我需要选择一个帖子,但条件如下所示:-

同时发布两个选定的术语。

我已经尝试过:-

SELECT p.ID, p.post_title FROM wp_posts p 
LEFT JOIN `wp_term_relationships` t
ON p.ID = t.object_id
LEFT JOIN `wp_term_taxonomy` tt
ON t.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.term_id =86
AND tt.term_id=39
GROUP BY t.object_id
HAVING COUNT( t.term_taxonomy_id ) =2
LIMIT 0,7

在这里,我想选择一个帖子,其术语 ID 为 86 和 39。这两个 ID 位于同一个表中。

最佳答案

这些表之间有什么关系?

这个选择有效,但我想你可以尝试另一种方法,你有标签而不是代码吗?无论如何,请检查一下。

SELECT 
p.ID
FROM
wp_posts p
LEFT JOIN wp_term_relationships t ON (p.ID = t.object_id)
WHERE
exists (
SELECT tt.term_taxonomy_id FROM wp_term_taxonomy tt
WHERE tt.term_taxonomy_id = t.term_taxonomy_id
and tt.term_id in(86,39)
)
group by p.ID
having count(p.ID) = 2

关于mysql - 选择带有术语 ID 的帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16602343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com