MySQL in-operator 必须匹配所有值?

发布于 2024-12-05 23:21:35 字数 292 浏览 7 评论 0原文

我已经建立了自己的论坛。在进行搜索时,我想找到两个(或更多)特定用户参与的任何线程。我想出了这个:

SELECT * FROM table1 INNER JOIN table2 
ON table1.threadid=table2.threadid 
WHERE table2.threadcontributor IN ('1','52512')

在意识到它实际上意味着'1' OR '52512'之前。

有什么方法可以让它工作,以便所有 id 都必须匹配吗?

I've made my own forum. When doing a search I want to find any threads where two (or more) specific users have participated. I came up with this:

SELECT * FROM table1 INNER JOIN table2 
ON table1.threadid=table2.threadid 
WHERE table2.threadcontributor IN ('1','52512')

Before realizing that it actually means '1' OR '52512'.

Is there any way to make it work so that all id's has to match?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝海似她心 2024-12-12 23:21:35
SELECT * 
    FROM table1 
        INNER JOIN table2 
            ON table1.threadid=table2.threadid 
    WHERE table2.threadcontributor IN ('1','52512')
    GROUP BY table1.PrimaryKey
    HAVING COUNT(DISTINCT table2.threadcontributor) = 2
SELECT * 
    FROM table1 
        INNER JOIN table2 
            ON table1.threadid=table2.threadid 
    WHERE table2.threadcontributor IN ('1','52512')
    GROUP BY table1.PrimaryKey
    HAVING COUNT(DISTINCT table2.threadcontributor) = 2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文